0 votes
by (120 points)

Logging into FileZilla, I can confirm that the file exists.

However, calling the rebex ftp client .FileExists always returns false.

Forcing it to do the rename (.Rename method) returns with a directory rename error. Any thoughts?

2019-03-19 17:03:04.052 Opening log file.
2019-03-19 17:03:04.058 INFO FileLogWriter(1)[11] Info: Assembly: Rebex.Common 2018 R4 for .NET 4.0-4.7
2019-03-19 17:03:04.065 INFO FileLogWriter(1)[11] Info: Platform: Windows 10.0.16299 64-bit; CLR: 4.0.30319.42000
2019-03-19 17:03:04.066 DEBUG FileLogWriter(1)[11] Info: Culture: en; Windows-1252
2019-03-19 17:03:58.891 INFO Ftp(1)[11] Info: Connecting to {redacted}:21 using Ftp.
2019-03-19 17:03:58.892 INFO Ftp(1)[11] Info: Assembly: Rebex.Ftp 2018 R4 for .NET 4.0-4.7
2019-03-19 17:03:58.892 INFO Ftp(1)[11] Info: Platform: Windows 10.0.16299 64-bit; CLR: 4.0.30319.42000
2019-03-19 17:03:58.892 DEBUG Ftp(1)[11] Info: Culture: en; Windows-1252
2019-03-19 17:03:58.893 INFO Ftp(1)[11] Info: Using proxy none.
2019-03-19 17:03:58.921 DEBUG Ftp(1)[11] Proxy: Connecting to {redacted}:21 (no proxy).
2019-03-19 17:03:59.183 DEBUG Ftp(1)[11] Info: Connection succeeded.
2019-03-19 17:03:59.439 INFO Ftp(1)[11] Response: 220 Hello, I'm freeFTPd 1.0
2019-03-19 17:04:04.836 INFO Ftp(1)[11] Command: USER imd_ph
2019-03-19 17:04:05.086 INFO Ftp(1)[11] Response: 331 Password required for imd_ph
2019-03-19 17:04:05.088 INFO Ftp(1)[11] Command: PASS **********
2019-03-19 17:04:05.339 INFO Ftp(1)[11] Response: 230 User imd_ph logged in
2019-03-19 17:04:05.340 INFO Ftp(1)[11] Command: FEAT
2019-03-19 17:04:05.592 INFO Ftp(1)[11] Response: 211-Extensions supported
2019-03-19 17:04:05.592 INFO Ftp(1)[11] Response: 211-MODE Z
2019-03-19 17:04:05.592 INFO Ftp(1)[11] Response: 211 End of FEAT
2019-03-19 17:06:12.759 INFO Ftp(1)[11] Command: TYPE I
2019-03-19 17:06:13.011 INFO Ftp(1)[11] Response: 200 TYPE set to BINARY
2019-03-19 17:06:13.063 INFO Ftp(1)[11] Command: SIZE .
2019-03-19 17:06:13.314 INFO Ftp(1)[11] Response: 550 .: No such file or directory.
2019-03-19 17:06:13.364 INFO Ftp(1)[11] Command: PWD
2019-03-19 17:06:13.616 INFO Ftp(1)[11] Response: 257 "/" is current directory
2019-03-19 17:06:13.667 INFO Ftp(1)[11] Command: SIZE /
2019-03-19 17:06:13.919 INFO Ftp(1)[11] Response: 550 /: No such file or directory.
2019-03-19 17:06:13.970 INFO Ftp(1)[11] Command: SIZE /b5a58610-8168-46a0-bb2f-d8a2b6be480f.mov
2019-03-19 17:06:14.222 INFO Ftp(1)[11] Response: 550 /b5a58610-8168-46a0-bb2f-d8a2b6be480f.mov: No such file or directory.
2019-03-19 17:06:22.819 INFO Ftp(1)[11] Command: RNFR /b5a58610-8168-46a0-bb2f-d8a2b6be480f.mov
2019-03-19 17:06:23.072 INFO Ftp(1)[11] Response: 350 Go ahead, enter destination name
2019-03-19 17:06:23.122 INFO Ftp(1)[11] Command: RNTO //New Name.mov
2019-03-19 17:06:23.375 INFO Ftp(1)[11] Response: 450 Directory rename error
2019-03-19 17:06:23.430 ERROR Ftp(1)[11] Info: Rebex.Net.FtpException: Directory rename error (450).
   at Rebex.Net.Ftp.aujt(Int32 cw, Boolean cx)
   at Rebex.Net.Ftp.aumn(String hv, String hw)
2019-03-19 17:06:36.769 INFO Ftp(1)[11] Command: SIZE //New Name.mov
2019-03-19 17:06:37.019 INFO Ftp(1)[11] Response: 213 110908443
2019-03-19 17:06:42.179 INFO Ftp(1)[11] Command: RNFR /b5a58610-8168-46a0-bb2f-d8a2b6be480f.mov
2019-03-19 17:06:42.430 INFO Ftp(1)[11] Response: 350 Go ahead, enter destination name
2019-03-19 17:06:42.480 INFO Ftp(1)[11] Command: RNTO //New Name.mov
2019-03-19 17:06:42.731 INFO Ftp(1)[11] Response: 450 Directory rename error
2019-03-19 17:06:42.732 ERROR Ftp(1)[11] Info: Rebex.Net.FtpException: Directory rename error (450).
   at Rebex.Net.Ftp.aujt(Int32 cw, Boolean cx)
   at Rebex.Net.Ftp.aumn(String hv, String hw)
2019-03-19 17:07:27.482 INFO Ftp(1)[11] Command: QUIT
2019-03-19 17:07:27.733 INFO Ftp(1)[11] Response: 221 Goodbye!
Applies to: Rebex FTP/SSL

1 Answer

0 votes
by (72.7k points)

It seems that you are using absolute paths, which can cause troubles on the server. Try to use relative paths only.

Please instead of:

ftp.FileExists("/b5a58610-8168-46a0-bb2f-d8a2b6be480f.mov");
ftp.Rename("/b5a58610-8168-46a0-bb2f-d8a2b6be480f.mov", "//New Name.mov");

Try this:

ftp.FileExists("b5a58610-8168-46a0-bb2f-d8a2b6be480f.mov");
ftp.Rename("b5a58610-8168-46a0-bb2f-d8a2b6be480f.mov", "New Name.mov");

Also please note the Ftp.FileExists() method documentation:

Detects whether the specified file exists on the server. Not all FTP
servers support this!

The standard FTP protocol does not have a dedicated command that could
be used to detect whether a file exists. There is the MLST command
that is quite reliable, but not all server support it and we have to
rely on SIZE or even PWD, CWD commands for these servers.

by (120 points)
Thanks for that. I would give that a try.

One thing to note is that, this was working for Rebex.Ftp 4.0.5466.0.
We upgraded dependencies to Rebex.Ftp 4.0.6930.0 and this started failing.
by (72.7k points)
Can you please share the log from the version Rebex.Ftp 4.0.5466.0?
Analyzing the difference will be very useful.
by (120 points)
Here's a log of  4.0.5466.0.
I've annotated the logs with when the RebexFTP calls

2019-03-21 15:12:09.277 Opening log file.
2019-03-21 15:12:09.277 Using FileLogWriter version 2.0.5466.0.
2019-03-21 15:12:09.299 INFO Ftp(1)[5] Info: Connecting to {{ipaddress}}:21 using Ftp 4.0.5466.0.
2019-03-21 15:12:09.300 INFO Ftp(1)[5] Info: Using proxy none.
2019-03-21 15:12:09.593 DEBUG Ftp(1)[5] Info: Connection succeeded.
2019-03-21 15:12:09.846 INFO Ftp(1)[5] Response: 220 Hello, I'm freeFTPd 1.0
2019-03-21 15:12:09.854 INFO Ftp(1)[5] Command: USER imd_ph
2019-03-21 15:12:10.105 INFO Ftp(1)[5] Response: 331 Password required for imd_ph
2019-03-21 15:12:10.108 INFO Ftp(1)[5] Command: PASS ********
2019-03-21 15:12:10.387 INFO Ftp(1)[5] Response: 230 User imd_ph logged in
2019-03-21 15:12:10.388 INFO Ftp(1)[5] Command: FEAT
2019-03-21 15:12:10.640 INFO Ftp(1)[5] Response: 211-Extensions supported
2019-03-21 15:12:10.640 INFO Ftp(1)[5] Response: 211-MODE Z
2019-03-21 15:12:10.640 INFO Ftp(1)[5] Response: 211 End of FEAT

-- FtpClient.FileExists("/b5a58610-8168-46a0-bb2f-d8a2b6be480f.mov") => Returns TRUE
2019-03-21 15:13:00.974 INFO Ftp(1)[5] Command: TYPE I
2019-03-21 15:13:01.225 INFO Ftp(1)[5] Response: 200 TYPE set to BINARY
2019-03-21 15:13:01.277 INFO Ftp(1)[5] Command: SIZE .
2019-03-21 15:13:01.530 INFO Ftp(1)[5] Response: 550 .: No such file or directory.
2019-03-21 15:13:01.580 INFO Ftp(1)[5] Command: PWD
2019-03-21 15:13:01.833 INFO Ftp(1)[5] Response: 257 "/" is current directory
2019-03-21 15:13:01.884 INFO Ftp(1)[5] Command: SIZE /
2019-03-21 15:13:02.140 INFO Ftp(1)[5] Response: 550 /: No such file or directory.
2019-03-21 15:13:02.190 INFO Ftp(1)[5] Command: SIZE /b5a58610-8168-46a0-bb2f-d8a2b6be480f.mov
2019-03-21 15:13:02.443 INFO Ftp(1)[5] Response: 213 112357617
2019-03-21 15:13:02.494 INFO Ftp(1)[5] Command: PWD
2019-03-21 15:13:02.746 INFO Ftp(1)[5] Response: 257 "/" is current directory
2019-03-21 15:13:02.796 INFO Ftp(1)[5] Command: CWD /b5a58610-8168-46a0-bb2f-d8a2b6be480f.mov
2019-03-21 15:13:03.054 INFO Ftp(1)[5] Response: 550 /b5a58610-8168-46a0-bb2f-d8a2b6be480f.mov: no such file or directory

-- FtpClient.Rename("/b5a58610-8168-46a0-bb2f-d8a2b6be480f.mov","//New Name.mov") => First rename throws
2019-03-21 15:14:01.408 INFO Ftp(1)[5] Command: RNFR /b5a58610-8168-46a0-bb2f-d8a2b6be480f.mov
2019-03-21 15:14:01.660 INFO Ftp(1)[5] Response: 350 Go ahead, enter destination name
2019-03-21 15:14:01.710 INFO Ftp(1)[5] Command: RNTO //New Name.mov
2019-03-21 15:14:01.963 INFO Ftp(1)[5] Response: 450 Directory rename error
2019-03-21 15:14:01.970 ERROR Ftp(1)[5] Info: Rebex.Net.FtpException: Directory rename error (450).
   at Rebex.Net.Ftp.CM(Int32 A, Boolean B)
   at Rebex.Net.Ftp.OO(String A, String B)
   
-- FtpClient.FileExists("//New Name.mov") => Check if rename exists ?
2019-03-21 15:15:01.569 INFO Ftp(1)[5] Command: SIZE //New Name.mov
2019-03-21 15:15:01.822 INFO Ftp(1)[5] Response: 550 //New Name.mov: No such file or directory.

-- FtpClient.Rename("/b5a58610-8168-46a0-bb2f-d8a2b6be480f.mov","//New Name.mov") => Second rename is successful (retry mechanism)
2019-03-21 15:16:32.245 INFO Ftp(1)[5] Command: RNFR /b5a58610-8168-46a0-bb2f-d8a2b6be480f.mov
2019-03-21 15:16:32.497 INFO Ftp(1)[5] Response: 350 Go ahead, enter destination name
2019-03-21 15:16:32.548 INFO Ftp(1)[5] Command: RNTO //New Name.mov
2019-03-21 15:16:32.802 INFO Ftp(1)[5] Response: 250 RNTO command successful

2019-03-21 15:17:07.817 INFO Ftp(1)[5] Command: QUIT
2019-03-21 15:17:08.069 INFO Ftp(1)[5] Response: 221 Goodbye!
by (72.7k points)
I have compared the two logs and the conclusion is:
Rebex client sends always same commands for FileExists() and Rename(), but the server replies differently.

The only meaniangful explanation is that the state on the server was different (in old log, the file existed, but it doesn't exist when creating new log).

In old log you can see that for FileExists(), the server returned size for the file:
2019-03-21 15:13:02.190 INFO Ftp(1)[5] Command: SIZE /b5a58610-8168-46a0-bb2f-d8a2b6be480f.mov
2019-03-21 15:13:02.443 INFO Ftp(1)[5] Response: 213 112357617

While in the new log, the server returned no such file:
2019-03-19 17:06:13.970 INFO Ftp(1)[11] Command: SIZE /b5a58610-8168-46a0-bb2f-d8a2b6be480f.mov
2019-03-19 17:06:14.222 INFO Ftp(1)[11] Response: 550 /b5a58610-8168-46a0-bb2f-d8a2b6be480f.mov: No such file or directory.

For the rename, it is similar. Old log shows that the file is not on the server:
2019-03-21 15:15:01.569 INFO Ftp(1)[5] Command: SIZE //New Name.mov
2019-03-21 15:15:01.822 INFO Ftp(1)[5] Response: 550 //New Name.mov: No such file or directory.

But in the new log, it shows that the target file is there:
2019-03-19 17:06:36.769 INFO Ftp(1)[11] Command: SIZE //New Name.mov
2019-03-19 17:06:37.019 INFO Ftp(1)[11] Response: 213 110908443


I think, that the code will work with newer version as well.
But at first, please ensure manually (e.g. using FileZilla) that the file "/b5...0f.mov" exists on the server and the file "/New Name.mov" does not exists on the server.
...