Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Not Able to fetch file from ftp server using net::SFTP

by sachin raj aryan (Acolyte)
on Dec 13, 2019 at 05:55 UTC ( [id://11110050]=perlquestion: print w/replies, xml ) Need Help??

sachin raj aryan has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks !!!! I am trying to fetch one file from report server Linux based server but file is not coming in local directory and even no error it is throwing.Please help me out why files are not downloading am I missing smthing

#!/usr/bin/perl use Net::SFTP; use IO::Uncompress::Gunzip qw(gunzip $GunzipError); use Date::Simple qw(d8); use DBI; use DBIx::Dump; use Time::Piece; use Time::Seconds 'ONE_DAY'; my $host = "10.x.x.x"; my $user = "xxx"; my $password = "xxx"; my $basedir = "locations"; my$reportfldr = "reports"; my $reportdr ="Reports_On_Request"; my $filename = 'List1.txt'; $date = $ARGV[0]; # date is your first argument{ FORMAT + (20161125)}#### uncomment this line and enter date while running s +cript if #you want to manually fetch report and commnet below + block #autodate # my $out = qx(net time); #toget current date # my @sachin = split/\s+/,$out; #toget current date au +todate # print "$sachin[5] \n"; #toget current date autodate # my @datesys = split/-/,$sachin[5]; #toget current date aut +odate # my $dt_column = join ("",$datesys[2],$datesys[1],$datesys[0]); #tog +et current date autodate # $date =$dt_column; #toget current date autodate # my $yesterday= (localtime() -ONE_DAY)->ymd(''); #autodate # print "$yesterday \n"; #autodate # $date = $yesterday; #autodate #Starting of Main Program # my $d = d8($date); my $error_log=$d-> format ('%d/%b/%Y'); #my $brchid="b00330"; ####brchid it is reading from branchList file + ##### open (STDERR,">",$error_log) ; ############Fetching report from LHO Server########################## +############## open(my $fh, '<:encoding(UTF-8)', $filename)or die "Could not open f +ile '$filename' $!"; while ( my $line = <$fh>) { chomp $line; my @splitline=split/[|]/,$line; my $brchid = $splitline[0]; my $region = $splitline[1]; my $netwrk = $splitline[2]; my $mod = $splitline[3]; my $rg = $splitline[4]; my $branchname = $splitline[5]; print "Starting $branchname\t"; $brnchid = substr $brchid,1 ; print "$brnchid upload \n"; system "mkdir $brchid"; chdir($brchid); system "mkdir $date"; chdir ($date); my $dir = join"/",$basedir,$brchid,$reportfldr,$date,$reportdr; print "$dir"; print " FTP is ongoing in main file \n"; my %args =( user =>'lho',password=>'lho',port=>22,debug=>'true'); my $f = Net::SFTP->new($host,%args); $f->ls($dir,sub {print $_[0]->{filename},"\n"}); my $file = join "/",$dir,"Status_Report_For_BGL_gend7058.txt.gz"; print "$file, i m sachin \n"; $f->get($file); #$f->exit;

Logs are as under

subdirectory or file b01253 already exists. A subdirectory or file 20191204 already exists. locations/b01253/reports/20191204/Reports_On_Request FTP is ongoing i +n main file I03977DE207: Reading configuration data C:\Users\5692032\.ssh\config I03977DE207: Reading configuration data C:\windows\ssh_config I03977DE207: Connecting to 10.31.0.35, port 22. I03977DE207: Remote version string: SSH-2.0-OpenSSH_5.3 I03977DE207: Remote protocol version 2.0, remote software version Ope +nSSH_5.3 I03977DE207: Net::SSH::Perl Version 2.14, protocol version 2.0. I03977DE207: No compat match: OpenSSH_5.3. I03977DE207: Connection established. I03977DE207: Sent key-exchange init (KEXINIT), waiting for response. I03977DE207: Using diffie-hellman-group-exchange-sha256 for key excha +nge I03977DE207: Host key algorithm: ssh-rsa I03977DE207: Algorithms, c->s: aes256-ctr hmac-sha2-512 none I03977DE207: Algorithms, s->c: aes256-ctr hmac-sha2-512 none I03977DE207: Entering Diffie-Hellman Group Exchange. I03977DE207: SSH2_MSG_KEX_DH_GEX_REQUEST(2048<4096<8192) sent I03977DE207: Sent DH Group Exchange request, waiting for reply. I03977DE207: Received 4096 bit DH Group Exchange reply. I03977DE207: Generating new Diffie-Hellman keys. I03977DE207: Entering Diffie-Hellman key exchange. I03977DE207: Sent DH public key, waiting for reply. I03977DE207: Received host key, type 'ssh-rsa'. I03977DE207: Host '10.31.0.35' is known and matches the host key. I03977DE207: Verifying server signature. I03977DE207: Send NEWKEYS. I03977DE207: Waiting for NEWKEYS message. I03977DE207: Enabling encryption/MAC/compression. I03977DE207: Sending request for user-authentication service. I03977DE207: Service accepted: ssh-userauth. I03977DE207: Trying empty user-authentication request. I03977DE207: Authentication methods that can continue: publickey,gssa +pi-keyex,gssapi-with-mic,password. I03977DE207: Next method to try is publickey. I03977DE207: Next method to try is password. I03977DE207: Trying password authentication. I03977DE207: Login completed, opening dummy shell channel. I03977DE207: channel 0: new [client-session] I03977DE207: Requesting channel_open for channel 0. I03977DE207: channel 0: open confirm rwindow 0 rmax 32768 I03977DE207: channel 1: new [client-session] I03977DE207: Requesting channel_open for channel 1. I03977DE207: Sending subsystem: sftp I03977DE207: Requesting service subsystem on channel 1. I03977DE207: channel 1: open confirm rwindow 0 rmax 32768 I03977DE207: sftp: Sending SSH2_FXP_INIT I03977DE207: sftp: Remote version: 3 I03977DE207: sftp: Sent message T:11 I:0 I03977DE207: sftp: Sent message T:12 I:1 I03977DE207: sftp: Received reply T:104 I:1 I03977DE207: sftp: Received 11 SSH2_FXP_NAME responses Report_Maturing_Securities_lond2443.txt.gz Advances_Against_shares_lond2395.txt.gz Customer_Insurance_report_lond2393.txt.gz .. Coll_Matured_Sec_lond2444.txt.gz limits_sanctioned_to_sugar_mills_lond2484.txt.gz . Overdue_Loans_Lond2497.txt.gz ListOfNonZeroIntermediateSuspenseAccounts-gend0804.txt.gz SDV_Summary_SY0203.prt.gz Status_Report_For_BGL_gend7058.txt.gz I03977DE207: sftp: Sent message T:12 I:2 I03977DE207: sftp: Received reply T:101 I:2 I03977DE207: sftp: Received SSH2_FXP_STATUS 1 I03977DE207: sftp: Sent message T:4 I:3 locations/b01253/reports/20191204/Reports_On_Request/Status_Report_Fo +r_BGL_gend7058.txt.gz, i m sachin I03977DE207: sftp: Sent message T:17 I:4 I03977DE207: sftp: Received stat reply T:105 I:4 I03977DE207: sftp: Sent SSH2_FXP_OPEN I:5 P:locations/b01253/reports/ +20191204/Reports_On_Request/Status_Report_For_BGL_gend7058.txt.gz I03977DE207: sftp: Sent message SSH2_FXP_READ I:6 O:0 I03977DE207: sftp: Received reply T:103 I:6 I03977DE207: sftp: In read loop, got 10279 offset 0 I03977DE207: sftp: Sent message SSH2_FXP_READ I:7 O:10279 I03977DE207: sftp: Received reply T:101 I:7 I03977DE207: sftp: Sent message T:4 I:8 FTP done

Replies are listed 'Best First'.
Re: Not Able to fetch file from ftp server using net::SFTP
by bliako (Monsignor) on Dec 13, 2019 at 07:19 UTC

    Net::SFTP's manual states this:

    $local is optional. If not provided, the contents of the remote file $remote will be either discarded, if get is called in void context, or returned from get if called in a non-void context. Presumably, in the former case, you will use the callback function \&callback to "do something" with the contents of $remote.
    

    you need to specify a local filename to save remote file to. (and make sure destination dirs exist before saving)

    bw, bliako

      thanks a lot for such a good explaination ...Issue resolved !!!<\p>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11110050]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-24 10:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found