in reply to FTP within PERL script WITHOUT NET::FTP?

This should work with a gateway, this is working code with some modified names.

my $gsRemoteMachine = "ftp.site.com"; my $gsRemoteDir = "/"; my $gsFtpId = "username"; my $gsFtpPwd = "password"; my $gsGateMachine = "gateway.site.com"; # ftp gateway my $gsGateConnect = "\@$gsRemoteMachine "; # remote machine connect +id for gateway my $gsRemoteMachine = $gsGateMachine; my $gsFeedsDir = "/mypath/"; my $gsFeedFile = "myfile"; system("ftp -n $RemoteMachine <<EOF> $StatusFile 2>&1\n\nuser $gsFtpId +$gsGateConnect $gsFtpPwd\nverbose\n$gsFtpMode\nput $gsFeedsDir$gsFeed +File $gsRemoteDir$gsFeedFile\nclose\nbye\nEOF");
Update:Posted this real early this morning, didn't really put any meaningful comments. Note that the above is only tested on a unix box (HPUX), but should work as is on any *nix. The contents of "$StatusFile" would look about like:
Verbose mode on.
200 Type set to I.
200 PORT command successful.
150 Opening BINARY mode data connection for xxxxxxx.gz.
226 Transfer complete.
720203 bytes sent in 5.00 seconds (140.57 Kbytes/s)
221- Goodbye...
221  Total bytes retrieved: 0   stored: 720203

Without Net::FTP one needs to open the $StatusFile and read it in to determine if it succeeded/failed.

I have more on this very issue, in a previous node here Improving an FTP process that discusses FTPing this way, and why I migrated such code to Net::FTP

Replies are listed 'Best First'.
RE: Re: FTP within PERL script WITHOUT NET::FTP?
by c-era (Curate) on Nov 13, 2000 at 21:35 UTC
    The above method would probably be the best, you may want to check if you are on a Win32 or Unix platform, and call the appropriate ftp programs. If you would like to actually write your own ftp client, I don't recomend it (although it can be a good learning experiance), you should read some of the RFCs. Here is some c source code that may also help you.