psftp randomly fails with local: unable to open

Carolina-Trader picture Carolina-Trader · Apr 21, 2015 · Viewed 7.7k times · Source

psftp put fails about one percent of the time with example being

local: unable to open d:\\WorkPath\\F_56MTV56201504201707224380.csv

  1. Calling application has needed rights to directory path where file exists and to upload file itself
  2. Directory path where upload file resides is not locked down. See item (1)
  3. csv file to be uploaded is created in C++ with fclose() function not returning EOF upon closing the file
  4. Directory upload path has been excluded from antivirus
  5. 99 out of 100 uploads work as expected
  6. Reuploading failed upload file by calling same batch works fine
  7. Solution is multithreaded

The only thing I can see doing different at this point is using lcd command with local filename and not using fully qualified path but in theory, this shouldn't change anything or am I missing something?

Example batch file:

"D:\\Program Files\\ApplicationPath\\psftp.exe" ^
    1.2.3.4 -l username -pw password -batch -bc ^
    -b "d:\\\\WorkPath\\\\\EXMSP35201504210946233890.script" ^ 
    > "d:\\\\WorkPath\\\\\EXMSP35201504210946233890.script.log" 2>&1

Example script file:

put d:\\\\WorkPath\\\\EXMSP35201504210946233890.csv
bye

The D: looks like a physical disk attached to the server, however, the server, 2008R2 is on a VMWare Virtual Platform.

Answer

Martin Prikryl picture Martin Prikryl · Apr 22, 2015

Use some WinAPI logger to find out, why an underlying CreateFile WinAPI function call is failing.


Or use a different SFTP client with more detailed error messages.

For example, an equivalent WinSCP script is:

winscp.com /command ^
    "option echo on" ^
    "open sftp://username:[email protected]/" ^
    "put d:\WorkPath\EXMSP35201504210946233890.csv" ^
    "exit" > d:\WorkPath\EXMSP35201504210946233890.script.log

With WinSCP you'd get an error like:

File or folder 'd:\WorkPath\EXMSP35201504210946233890.csv' does not exist.
System Error. Code: 3.

The system cannot find the path specified.

See an introduction to WinSCP scripting.

(I'm the author of WinSCP)


You should not be using double backslashes in paths. Though Windows tolerate that.