Question:
We're having an issue uploading files to a particular SFTP server.
From what I can tell, I think this server may not allow the automatic FXP_FSTAT called after opening a file. Is there a way to disable this?
Here's an example failed upload attempt:
OpenFile:
DllDate: Oct 19 2016
ChilkatVersion: 9.5.0.62
UnlockPrefix: ------
Architecture: Little Endian; 64-bit
Language: Linux Perl
VerboseLogging: 1
SshVersion: SSH-2.0-TIBCO BusinessConnect Plug-in for SFTP Server
SftpVersion: 3
sftpOpenFile:
remotePath: /2967115.txt
access: writeOnly
createDisposition: createNew,blockWrite,blockDelete,blockRead
v3Flags: 0x2a
sendPacket:
channelSendData2:
sendMessageInOnePacket:
(leaveContext 1ms)
(leaveContext 1ms)
(leaveContext 1ms)
Sent FXP_OPEN
readSftpPacket:
readChannelData:
dataLen: 38
clientWinSize: 327633
(leaveContext 194ms)
(leaveContext 194ms)
handle: 32313837353530393436363235323638333231343139303639
(leaveContext 195ms)
Success.
(leaveContext 195ms)
WriteFileText:
DllDate: Oct 19 2016
ChilkatVersion: 9.5.0.62
UnlockPrefix: -------
Architecture: Little Endian; 64-bit
Language: Linux Perl
VerboseLogging: 1
SshVersion: SSH-2.0-TIBCO BusinessConnect Plug-in for SFTP Server
SftpVersion: 3
handle: 32313837353530393436363235323638333231343139303639
charset: ansi
getFileSize:
fetchAttributes:
bFollowLinks: 0
bIsHandle: 1
bSizeOnly: 0
handle: 32313837353530393436363235323638333231343139303639
serverVersion: 3
Using FXP_FSTAT
sendPacket:
channelSendData2:
sendMessageInOnePacket:
(leaveContext)
(leaveContext)
(leaveContext)
Sent message to fetch attributes.
readSftpPacket:
readChannelData:
dataLen: 21
clientWinSize: 327612
(leaveContext 162ms)
(leaveContext 162ms)
StatusResponseFromServer:
Request: FXP_FSTAT
InformationReceivedFromServer:
StatusCode: 4
StatusMessage:
(leaveContext)
(leaveContext)
(leaveContext 162ms)
(leaveContext 162ms)
offset: 0
writeDataSource:
serverWindowSize: 130941
Using specialized upload for small server window size...
smallWindowSizeUpload:
startingOffset: 0
uploadChunkSize: 1024
serverWindowSize: 130941
sendPacket:
channelSendData2:
sendMessageInOnePacket:
(leaveContext)
(leaveContext 1ms)
(leaveContext 1ms)
***TRUNCATED***
sendPacket:
channelSendData2:
sendMessageInOnePacket:
(leaveContext)
(leaveContext)
(leaveContext 1ms)
End of data stream...
------------------------------------------------
getWriteStatusReplies:
StatusResponseFromServer:
Request: SSH_FXP_WRITE
InformationReceivedFromServer:
StatusCode: 4
StatusMessage:
(leaveContext)
(leaveContext)
(leaveContext 197ms)
totalNumBytesSent: 37981
totalTimeSendingMs: 11
totalTimeReadingMs: 0
(leaveContext 208ms)
(leaveContext 208ms)
Success.
(leaveContext 371ms)
CloseHandle:
DllDate: Oct 19 2016
ChilkatVersion: 9.5.0.62
UnlockPrefix: NIHALTSSH
Architecture: Little Endian; 64-bit
Language: Linux Perl
VerboseLogging: 1
SshVersion: SSH-2.0-TIBCO BusinessConnect Plug-in for SFTP Server
SftpVersion: 3
handle: 32313837353530393436363235323638333231343139303639
sftpCloseHandle:
handle: 32313837353530393436363235323638333231343139303639
sendPacket:
channelSendData2:
sendMessageInOnePacket:
(leaveContext)
(leaveContext)
(leaveContext)
Sent FXP_CLOSE
readSftpPacket:
readChannelData:
dataLen: 21
clientWinSize: 327570
(leaveContext 4ms)
(leaveContext 4ms)
StatusResponseFromServer:
Request: FXP_CLOSE
InformationReceivedFromServer:
StatusCode: 4
StatusMessage:
(leaveContext)
(leaveContext)
Received a failed status response.
(leaveContext 5ms)
Failed.
(leaveContext 6ms)
OK, I found that if I send a file using the UploadFileByName method, the library does not attempt to get the file attributes using FXP_FSTAT.
But when uploading data that's in memory, using openFile,WriteFileBytes,CloseHandle the FXP_FSTAT is automatic.
Is that necessary? Would be great if I could disable this.
Thanks!
The FXP_FSTAT is not the cause of the problem. Your server has no trouble with it.
Also, the FXP_FSTAT is required, because an SFTP packet to write data to a file must specify an offset. To append to a file, one must know the size of the file so the correct SFTP write packet (with the correct offset) can be sent.
In this case, the UploadFileByName is suppressing the erroneous non-success response to the FXP_CLOSE. Your application can simply do the same..
Thanks for your reply.
Doesn't the log indicate it is trying to get the file attributes on the newly opened file before sending data? But receives a "StatusCode: 4" back?
getFileSize:
fetchAttributes:
bFollowLinks: 0
bIsHandle: 1
bSizeOnly: 0
handle: 32313837353530393436363235323638333231343139303639
serverVersion: 3
Using FXP_FSTAT
sendPacket:
channelSendData2:
sendMessageInOnePacket:
(leaveContext)
(leaveContext)
(leaveContext)
Sent message to fetch attributes.
readSftpPacket:
readChannelData:
dataLen: 21
clientWinSize: 327612
(leaveContext 162ms)
(leaveContext 162ms)
StatusResponseFromServer:
Request: FXP_FSTAT
InformationReceivedFromServer:
StatusCode: 4
StatusMessage:
(leaveContext)
(leaveContext)
(leaveContext 162ms)
(leaveContext 162ms)
The remote server also acts like the file transfer was not successful, so ignoring the failure to close won't work.
However, UploadFileByName doesn't appear to request the file attributes on the new file immediately before writing to it.
ServerInitialWindowSize: 0
uploadFileByName:
remoteFilePath: /2969065.TXT
localFilePath: /2969065.TXT
remoteFilePathUtf8_QP: /2969065.TXT
localFilePathUtf8_QP: /2969065.TXT
localFileSize: 246816
sftpOpenFile:
filepathUtf8_QP: /2969065.TXT
remotePath: /2969065.TXT
access: writeOnly
createDisposition: createTruncate
v3Flags: 0x1a
sendPacket:
channelSendData2:
(leaveContext)
(leaveContext 1ms)
Sent FXP_OPEN
readSftpPacket:
readChannelData:
(leaveContext 162ms)
(leaveContext 162ms)
handle: 3232373139373730303231353833393131303132343931313939
(leaveContext 163ms)
timeToOpenMs: Elapsed time: 163 millisec
uploadFile:
socketOptions:
SO_SNDBUF: 262142
SO_RCVBUF: 262142
TCP_NODELAY: 1
SO_KEEPALIVE: 0
(leaveContext)
handle: 3232373139373730303231353833393131303132343931313939
fromLocalPath: /2969065.TXT
sendAheadMaxCount: 12
localFileSize2: 246816
writeDataSource:
startingOffset: 0
uploadChunkSize: 32000
sendPacket:
channelSendData2:
(leaveContext 1ms)
(leaveContext 1ms)
Thanks. I think the correct behavior is that the WriteFileText should've returned a failed status. I don't think the FXP_FSTAT matters -- the server responded to both it and the FXP_WRITE with a status code of 4 (failure).
It may be that your call to OpenFile passed an absolute path:
remotePath: /2967115.txt access: writeOnly createDisposition: createNew,blockWrite,blockDelete,blockReadI would think the server would interpret this as wanting to create the file "2967115.txt" in the filesystem's root directory. Try opening "2967115.txt" without the "/" to open/create a file in the HOME directory of your SSH user account, which is probably what you want, right?
Also, some servers can be picky or fragile with "writeOnly". Try "readWrite" instead. Also.. only use "blockWrite,blockDelete, etc. " if you know for sure that you want it.
PS> I'm testing the sequence of OpenFile, WriteFileText, and CloseFile, and will simulate an error to verify the behavior is correct (and will fix if not..)
You're currently using v9.5.0.62. I tested v9.5.0.66 and the upload correctly fails if a status reply having value 4 (failure) is received.