LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-04-2010, 09:36 AM   #1
exceed1
Member
 
Registered: Mar 2008
Location: oslo
Distribution: debian,redhat
Posts: 199

Rep: Reputation: 31
Question SFTP throwing "End of file" when doing SFTP transfer in perl


Hi

I have an SFTP script that transfers a file over SFTP but just before its done uploading the file i get an "End of file" messages and it quits. I have checked the file uploaded to the server and compared it to the local file, the two seems to match. I cant imagine why im getting this error message when it seems like the transfer goes without any problems.

Has anyone experienced this kind of error before ? I had a similar problem with a script i wrote earlier, the script closed the connection too early, but i cant see that this is the situation here. The script is download a file from a windows server (using ssh) to a linux server, then uploading the file from the linux server to an ftp server using sftp. The downloading seems to go fine, no problems reported or seen, but the upload gives the error message even though the file' integrity seems to be fine.

Im using the Net::SFTP module and the put method to upload the file. Can anyone help on this problem?


--
regards,
chris
 
Old 03-04-2010, 10:54 AM   #2
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
What happens in your script after the upload is done ?
Are you using the \$callback method ?
http://search.cpan.org/dist/Net-SFTP..._\&callback_])

perl needs to output something at the end of a script or be told to exit.
 
Old 03-05-2010, 02:57 AM   #3
exceed1
Member
 
Registered: Mar 2008
Location: oslo
Distribution: debian,redhat
Posts: 199

Original Poster
Rep: Reputation: 31
After the upload is done the script writes out if the upload was complete or not. It checks this with a simple if-loop, it uses the fx2txt function in Net::SFTP to write the action error message which writes out "End of file". When i try to run the script when there is no files at the host its downloading from the script starts hanging a little when its connecting to the host its suppose to transfer files to and the script quits with a "Connection closed at <scriptname> <linenumber>".. in this situation there was no files in the directory on the server it downloads the files from so i guess its why it just hangs when it tries to upload files.

I have not had the possibility to run the script where there actually is files in the directory, since this is run on a production system and files are being downloaded from a server and uploaded to another server and then scripts at that server puts the files in a database (we dont have control of this DB) so then i cant just create test files on the server.

I have however tried manual sftp uploads to the server the files will be transfered to and it works without problems, so i guess this have to be a perl problem and not an sftp/ssh problem? As you mention, perl needs to output something, could you explain that a little further ?

I have added the debug option when creating the SFTP object now to be able to see more detailed whats happening, but ill have to wait for the output until there are any new files to transfer for the script.

Last edited by exceed1; 03-05-2010 at 05:05 AM.
 
Old 03-05-2010, 07:14 AM   #4
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
so is the SFTP the only error ?
the perl script runs and finishes gracefully ?

I would argue if it's an error at all, if the upload is actually complete.

You could always test that by running a checksum on the file. If the files ok, then the upload finished.
It's just how you deal with the message returned by the fx2txt function.
 
Old 03-06-2010, 11:59 AM   #5
exceed1
Member
 
Registered: Mar 2008
Location: oslo
Distribution: debian,redhat
Posts: 199

Original Poster
Rep: Reputation: 31
after more troubleshooting ive now found the soloution to the problem.. it was an error thrown by the sftp client program (error message received by the fx2txt function). The problem was in the error handling in the perl script.. the guy who had programmed it had misunderstood the usage of the status method in the net::sftp module, he though he could use the status method before the put method had been used.. and the status method is only going to be used after the put call has completed to check for possible errors.. he checked for a status code of 0 in return which is false in perl and since the status method always returns anything else than 0 on success the if loop would never work..

so a confusion about the usage of the module, what is true/false in perl and return codes in C. i hope i explained it good enough, post a reply if you want a better explaination i think its interesting to know the solution to these kind of problems, so i though i would share it..
 
Old 03-06-2010, 01:34 PM   #6
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
Well done.
Nice to know in future.
Thanks.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
perl script -> take a file that end in ".txt" cccc Programming 4 07-21-2009 01:58 PM
SFTP equivalent of FTP's "quot" command. jrobins Linux - Networking 3 10-04-2008 11:29 AM
File transfer using SFTP santhoshv Linux - Networking 1 09-18-2008 06:33 AM
transfer file using expect and sftp tanveer Linux - General 7 05-16-2008 10:29 AM
Poor file transfer speed with sftp six6 Fedora 3 07-29-2004 12:22 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration