SFTP throwing "End of file" when doing SFTP transfer in perl
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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.
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..
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.