This project is read-only.
1
Vote

PutFile() writes empty file on server when local file does not exist.

description

When calling PutFile() on a file which does not exist on the local machine, the FTPS library writes a 0-byte file on the FTP server.

This would appear to be because PutFile() opens the stream to the remote server before opening the local file.
      using (Stream s = PutFile(remoteFileName))
            return SendFile(localFileName, remoteFileName, s, transferCallback);
I have temporarily patched it in my copy of the code by doing an existence check inside PutFile like so:
    public ulong PutFile(string localFileName, string remoteFileName, FileTransferCallback transferCallback) {
        if (!File.Exists(localFileName))
            throw new FileNotFoundException(String.Format("{0} does not exist on the local machine."));

        using (Stream s = PutFile(remoteFileName))
            return SendFile(localFileName, remoteFileName, s, transferCallback);
    }
However, a better solution may be to open the local stream before opening the remote stream.

This turned out to be a big problem for us -- in our particular situation, we laid down a number of 0-byte files, but since our vendor denied us modify access to what we put on their server, there was no way we could correct the data after uploading it with their help, so this issue is of some real-world significance.

comments