|
I have run into an issue when trying to upload a file with a source local path that exceeds 260 characters to a GlobalScape EFT server. The PutFile method fails with an SftpException that says "The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters." You can reproduce this by making a file on your local C:\ drive that exceeds 260 characters. 1) Create Folder C:\LongPath 2) In C:\LongPath, create a 0 byte file named: "1bcdefghijklmnopqrstuvwxyz2bcdefghijklmnopqrstuvwxyz3bcdefghijklmnopqrstuvwxyz4bcd" + "efghijklmnopqrstuvwxyz5bcdefghijklmnopqrstuvwxyz6bcdefghijklmnopqrstuvwxyz7bcdefgh" + "ijklmnopqrstuvwxyz8bcdefghijklmnopqrstuvwxyz9bcdefghijklmnopqrstuvwxyz10bcdefgh.txt" 3) Rename C:\LongPath to C:\LongPathExceedsMaxPath 4) Attempt to upload the file. While I realize this problem is likely related to limitations in the .Net IO library, Microsoft provides a workaround to the 260 character limit by using a different naming convention and pre-pending the file paths with \\?\. With this naming convention and implementation it can support source paths up to 32,767 characters. The path would then be \\?\C:\LongPathExceedsMaxPath\1bcdedf.....gh.txt See the following link: http://msdn.microsoft.com/en-us/library/aa365247(v=vs.85).aspx#maxpath Once using the \\?\ naming convention, you may have to utilize the Kernel32 library methods CreateFile and ReadFile to open and read data from the file. I'm actually using BeginPutFile and EndPutFile to transfer the file asynchronously, but both methods show the same behavior. Is there any chance this is planned for a future build of Rebex SFTP? Thanks! |
|
You are right, this is actually a limitation of .NET's System.IO classes. Trying to open the file using System.IO.File.OpenRead(path) fails with the same exception. We will consider utilizing the \? naming convention for too-long paths in one of the next releases, but you can easily work around this with the current version of Rebex SFTP by using the stream based-API and the following custom stream object: C#:
With this class, you can open file stream using the \? naming convention and use them with Rebex SFTP API:
A similar approach will work with Perfect - I had not considered this approach. Thank you.
(21 Jul '11, 18:03)
Mike Mueller
|