Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2003
    san jose, CA

    Unanswered: how to close SFTP connection?

    Hello Everyone:

    I am uisng NET:FTP module to access a remote server. Everyone 5 minutes, there is cron job calling my script to
    upload file onto the remote server.

    I would like to knnow how can I close the SFTP connection without exiting my Perl script. I appreciate your advises and help!
    Would it be OK, If I don't close SFTP connection, will it affect the file transfer?

    My code snippet

    use Net:FTP;

    sub ftp_send() {
    my($file) = @_;
    $sftp = Net:FTP->new('xxx', user=>'zzz', password=>'yyy', debug=>1);
    $sftp->put("$homedir", "$remote");
    #close the SFTP connection here exit SFTP environment

    if ($sth->rows > 0)
    while($href = $sth->fetchrow_hashref()) {

    $filename = 'test.txt';
    open(out, ">>/home/$filename") || die("Couldn't open data file $!\n");
    print out $table;


  2. #2
    Join Date
    Oct 2002
    Baghdad, Iraq
    Looks like your post was hit by auto-smileys.

    It's based on Net:: SSH::Perl. If you dig around the source, you'll see that it has an attribute called {ssh}, which contains the actual ssh connection.

    Try opening a connection with debug=>1.

    Then try and undef your Net:: SFTP object and see if you get any indication that Net:: SFTP deleted itself.

    I didn't see a DESTROY block or a general close method in either module, so the debug statements may not say for certain. In that case, just have your script sit and wait for a while and in a separate terminal check whether the connection is closed with netstat -a -p tcp | grep ssh or something similar.

    There is also a mailing list dedicated to that module, you can try there.

    (Edit: removed smiley pollution)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts