anujkum_perl has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I am using Net::SFTP::Foreign to upload files to remote FTP server.Will it be possible that create a connection to FTP Server only one time and upload files whole day to FTP server ? I am using SFTP client to upload files in perl script. If any thing is not clear, Please tell me. It is very urgent for me... Thanks in advance..

Replies are listed 'Best First'.
Re: connect to FTP server once
by ww (Archbishop) on Aug 04, 2013 at 12:38 UTC
    You could try it. But that may be a rude (to the server) idea.

    In any case, you'll probably run into a timeout somewhere.

    If that's not clear, show us code and tell us why you need to avoid re-initiating your connection.
    If I've misconstrued your question or the logic needed to answer it, I offer my apologies to all those electrons which were inconvenienced by the creation of this post.
      thanks for you reply, The problem is that connecting to ftp server taking time around 1 min and I have to upload files as soon as files created in a directory ( a file created in a directory whenever any incident occur and this is a whole day activity). So I thought instead of making connection to ftp server , upload file then close connection, I should establish connection to FTP initially and upload files continously.Below I am sharing a code (I did not share complete script. I only share relevent part of script) ********************************************
      #!/bin/perl use Net::SFTP::Foreign; $sftp = Net::SFTP::Foreign->new($host, user => $user, port => $sport); $sftp->die_on_error("Unable to establish SFTP connection"); print LOGFILE "Connected to $host \n"; ##$appoutdir contain folder name where files resides. ## @ufiles variable contains name of files to be uploaded foreach $ufile (@ufiles) { print LOGFILE "Uploading file " . $ufile . "\n"; my($filename, $directories) = fileparse($ufile); $sftp->put("$appoutdir/$ufile", "$filename") or die "put failed: " . $sftp->error; move("$appoutdir/$filename","$apparchdir/$filename") or die "Moving to application processed directory failed: $!"; }
      **************************************** What parameter/other code could be to get desired functionality. Regards, ANUJ