If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Perl and the DBI > how to close SFTP connection?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-05-08, 00:21
sjgrad03 sjgrad03 is offline
Registered User
 
Join Date: Aug 2003
Location: san jose, CA
Posts: 68
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

#!/usr/bin/perl
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()) {
$optCount++;
&build_file($href);
}

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

}
Reply With Quote
  #2 (permalink)  
Old 09-20-08, 20:30
sco08y sco08y is offline
Registered User
 
Join Date: Oct 2002
Location: Baghdad, Iraq
Posts: 697
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)
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On