|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Hi there, Need urgent help with this problem!
Pardon, my knowledge of Perl and terms are minimal. Trying to survive. Usually I troubleshoot myself using google and devshed forums (thanks), but this time the problem I have, is driving me .I'm using NET::FTP on my ftp program. I'm able to log in/out and add/remove directories, but just can't get the upload part to work at all. I'm trying to upload the file "C:\\temp\\1\\4.jpg" to "ftp.mydomain2.com/root-www/cars/test4/test.jpg". The program always prints "problem1" at that point and does not upload anything. My program is located on mydomain1.net server and I'm trying to ftp on mydomain2.com server. I've been trying for over the weekend now and I'm running out of ideas. Here are few things I'm still thinking: - Why does everything else work? This is how I'm using mkdir and it works: Code:
sub makedir {
$reldir = $FORM{'directory'};
$absdir = "$data_ftp/$reldir";
if (not $ftp->cwd($absdir)) { # only create $absdir if it doesn't exist
$ftp->mkdir($absdir) or die "Unable to create $absdir";
&report("The directory <B><TT>$absdir</TT></B> has been created.");
}
else {
&report("The directory <B><TT>$absdir</TT></B> already exists.");
}
} # End of makedir subroutine.
Make dir works fine. Same goes for rmdir: Code:
$ftp->rmdir($absdir);
if (not $ftp->cwd($absdir)) {
&report("The directory <b><tt>$reldir</tt></b> has been removed.");
}
else {
&report("The directory <b><tt>$reldir</tt></b> was <b>not</b> removed,
because it was not empty.");
}
If those two work, why does not $ftp->put work? How the data (file) is transferred to the ftp? Do I still need to use <form> to get file to the buffer and then write the contents of the buffer to the new file? I thought with NET::FTP this would not be necessary. I think only source path/name and destination should be given and everything else is already included into NET:FTP, right? - Another thing that crossed my mind is, why should I be able to have a program on my website, which could easily upload files from visitors computer to my server? This would be too big security issue. I tested this program also on computer without anykind of firewall and did not work either. However, I'm still wondering, how people are using $ftp->put command without ability to steal visitors files? Maybe when used correctly, it asks the client if he is willing to upload file requested...? Even if I'm not trying to steal files, but use it legally and just for my clients, I'm wondering why it does not work and why should it work (if should at all). That's best I can currently think. I promised this to be working for the friend of mine within a week, so please help a.s.a.p.! Please ask if you need any other information to solve my problem. Thanks in advance, Temex Here is the actual test code I'm working with: -------------------------------------- Code:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Test1\n";
&open_ftp();
&ftp_upload();
$ftp->quit;
#########################################
sub ftp_upload {
print"<br><br>Upload:<hr>\n";
$ftp_pwd = $ftp->pwd();
print"\$ftp_pwd: $ftp_pwd<br>";
$filename = "C:\\temp\\1\\4.jpg";
$ftp->binary();
$ftp->put("$filename", ["$ftp_pwd\/test.jpg"]) or print "problem1<br>";
## I'm trying to upload the file "C:\\temp\\1\\4.jpg" to
the "ftp.mydomain2.com/root-www/cars/test4/test.jpg", but the program always prints "problem1" at this point and does not upload anything.
print"\n<hr>End of Upload<br><br>\n";
} # End of ftp_upload subroutine.
#########################################
sub open_ftp {
$server_name = "ftp.mydomain2.com";
$username = "******";
$password = "******";
$current_directory = "/root-www/cars/test4";
# All those 4 rows should be fine, since I'm able to login and add/remove dir's.
use Net::FTP;
$ftp = Net::FTP->new($server_name, Debug => 0)
or die "Cannot connect to $server_name: $@";
$ftp->login($username,$password)
or die "Cannot login ", $ftp->message;
$ftp->cwd($current_directory)
or die "Cannot change working directory ", $ftp->message;
$ftp_pwd = $ftp->pwd();
print"\$ftp_pwd: $ftp_pwd<br>";
print"\$current_directory: $current_directory<br>";
@dir_data = $ftp->dir();
print "File list<p><pre>\n";
foreach(@dir_data) {
print "$_\n";
}
print "\n</pre>Pass login subroutine ok\n";
}
-------------------------------------- Add on: I found out this: "It does not allow you to use streams other than STDIN" at http://www.perlmonks.org/index.pl?node_id=32298 . Is this the problem I'm having? I'm not taking file from the buffer, but just trying to transfer file using source and destination. |
|
#2
|
|||
|
|||
|
The brackets around REMOTE_FILE in the Net::FTP documentation for put() are not meant to be used literally; they are used to indicate that the REMOTE_FILE argument is optional. Remove the brackets and try it.
Code:
$ftp->put("$filename", "$ftp_pwd\/test.jpg") or print "problem1<br>";
austin
__________________
++$Posts; |
|
#3
|
|||
|
|||
|
I removed the [] -brackets, but does not work. Actually I did not had them before, but just tried if they would make any difference and forgot them on. Thanks anyways, it's a good start...heh..
I have also tried this: $ftp->put($filename, "test.jpg") or print "problem1<br>"; ..but does not work. I've been searching internet about this and the more I search, the more I think I'm misusing (=not using at all right now) the STDIN. Can you tell me if I must have a html form with <input name='filename' type='file'> included to get the file first to the buffer and _then_ use the ftp commands to save the buffer to specific destination? Or should it actually just work like those old funny dos commands: copy c:\pic.jpg a:\ This is the part, I don't currently understand too well and I think I'm totally trying to abuse it somehow now... Someone explain. Temex |
|
#4
|
|||
|
|||
|
Check on ftp server if you have permission to write files
|
|
#5
|
|||
|
|||
|
I think if he can make directories then he has permission to write.
|
|
#6
|
|||
|
|||
|
My permissions are set to rwxr-xr-x (755). Thanks for mentioning.
If you guys have working code using this command can you copy-paste the row, which shows how you use the $ftp->put($source, $destination) and also how you end up to those two variables ($source and $destination)? Also if someone can explain the STDIN littlebit and especially the part how it is related to the $ftp->put(). I think this is my problem, but just can't figure out how to get it right. Not easy to search google either because of all these $, -, >, : and other non-characters, but I'm not giving up. Will post back solution once it's found. Thanks again, Temex. |
|
#7
|
|||
|
|||
|
I have the exact same problem as Temex007. Did you (Temex007) or anyone else ever figure out a solution? Here is the code I am using:
Code:
use Net::FTP;
my $ftp;
$ftp = Net::FTP->new($ftp_server, Debug => 1)or die "Cannot connect to the ftp host - please contact $config{'sitename'} support: $@";
$ftp->login($login,$password)or die $ftp->message;
$ftp->pwd or die $ftp->message;
$ftp->cwd($upload_to_dir) or die $ftp->message;
$ftp->binary();
print "Uploading $input_file to $ftp_server: $upimagedirectory$new_file_name...<br>";
warn "Failed to set binary mode\n" unless
$ftp->put ( $input_file, $new_file_name ) or warn "did not upload"; #upload the main image
$ftp->quit;
My $input_file value is E:\\test\\2700.jpg for test purposes. I have also tried: e:\test\2700.jpg e:/test/2700.jpg e:/\test/\2700.jpg My $new_file_name value is new.jpg. My directory is permissions are currently 777 and I can log in just fine and use Net::FTP for other things like creating a directory. But "put" will not work my server returns my warning message in the error log at that line (no other info). I have talked to my server admin to see if it is a server problem. They swear everything is fine and have re-installed Net::FTP per my request. Here is the log of that: Net::FTP CPAN: Storable loaded ok Going to read /home/.cpan/Metadata Database was generated on Thu, 20 May 2004 22:34:02 GMT File::Spec is up to date. Digest::MD5 is up to date. Compress::Zlib is up to date. Archive::Tar is up to date. Data::Dumper is up to date. Net::Telnet is up to date. Net::Cmd is up to date. Term::ReadKey is up to date. Term::ReadLine::Perl is up to date. CPAN is up to date. Net::FTP is up to date. perlmod--Install done Any ideas? Can someone please give a correct format sample of how Net::FTP will pull a file to put? Or does anyone have other ideas for what I should be looking for? Your help is greatly appreciated! -Matt :) |
|
#8
|
|||
|
|||
|
Problem Solved for Net:FTP $ftp->put problem!
OK, I solved the problem, but it isn't good news. The short answer is that what both you and I are trying to do with Net::FTP cannot be done with Net::FTP.
The long answer is that Net::FTP is meant to have the host computer (running the script, in my case a Linux server) use Net::FTP to FTP to another computer to do things like copy files, transfer files, etc. So unless your home computer is set up as an FTP site then Net::FTP cannot go to it and retrieve a file. When you use Net::FTP in a script on a remote computer, it doesn't operate as an FTP program from your computer - it operates as an FTP program on the remote computer. If you have perl installed on your home computer, you can use a script using Net::FTP on that computer to FTP to a host computer and do all sorts of FTP stuff. But not the other way around, unless your home computer is also set up as an FTP host. This makes a lot of sense really. Otherwise, a script could be written quite easily to download the contents of your entire home computer by FTP! So I am working on a workaround to do the file transfers I want to do, but I don't know how to you. Good luck! Many thanks to the good monks at URL for helping me figure this out. -Matt ![]() |
![]() |
| Viewing: Dev Shed Forums > System Administration > FTP Help > NET::FTP $ftp->put problem! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|