Simple FTP rename doesn't work?!

mrd777

Member
Joined
Dec 4, 2014
Messages
7
Programming Experience
1-3
Hi guys,

Been at this for about 5 hours. no results on the web helping...

I am able to rename folders, but not actual files!

Code:
 Try


            Dim FOLDERrequest As FtpWebRequest = CType(FtpWebRequest.Create("ftp://" + myFtpHost + "/" + txtTarget.Text), FtpWebRequest)
            FOLDERrequest.Credentials = New System.Net.NetworkCredential(myFtpUser, myFtpPassword)
            FOLDERrequest.Method = WebRequestMethods.Ftp.Rename
            FOLDERrequest.KeepAlive = False
            FOLDERrequest.UsePassive = True


            FOLDERrequest.RenameTo = Trim(txtNewName.Text)
            FOLDERrequest.GetResponse()


        Catch ex As WebException
            Dim response As FtpWebResponse = DirectCast(ex.Response, FtpWebResponse)
            If response.StatusCode = FtpStatusCode.ActionNotTakenFileUnavailable Then   'Does not exist
                MsgBox(txtTarget.Text + " does not exist.")
            End If
           msgbox (ex.message)
        End Try
exception message is
the remote server returned an error 500 syntax error command unrecognized

Anyone?
Mr D
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,374
Location
Norway
Programming Experience
10+

mrd777

Member
Joined
Dec 4, 2014
Messages
7
Programming Experience
1-3
I would look at trace information, for example add app.config file to project and copy content from here: Using System.Net Tracing - Durgaprasad Gorti's WebLog - Site Home - MSDN Blogs (where it says "You can use the following configuration file")
It will output info to both Immediate window and the mentioned text file in output directory.
I'm stuck at this stupid thing again! I downloaded NETMON to monitor the network and this is what I see:
FTP:Request from Port 60994,'RNFR stores/1/items/aaa/DSC04412.JPG' {TCP:392, IPv4:961}
FTP:Response to Port 60994, '350 RNFR accepted - file exists, ready for destination' {TCP:392, IPv4:961}
FTP:Request from Port 60994,'RNTO stores/1/items/aaa/aa.jpg' {TCP:392, IPv4:961}
FTP:Response to Port 60994, '500 ?'
FTP:Response to Port 60994, '451 Rename/move failure: Invalid argument'

Any ideas?
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,374
Location
Norway
Programming Experience
10+
I'm stuck at this stupid thing again
Again? Does that mean that you weren't stuck in the mean time?
I downloaded NETMON to monitor the network
More complicated than I suggested, but it will get you the same information here.
FTP:Request from Port 60994,'RNFR stores/1/items/aaa/DSC04412.JPG' {TCP:392, IPv4:961}
FTP:Response to Port 60994, '350 RNFR accepted - file exists, ready for destination' {TCP:392, IPv4:961}
FTP:Request from Port 60994,'RNTO stores/1/items/aaa/aa.jpg' {TCP:392, IPv4:961}
FTP:Response to Port 60994, '500 ?'
FTP:Response to Port 60994, '451 Rename/move failure: Invalid argument'
I don't see the problem, maybe a problematic FTP server? I can see from "RNTO stores/1/items/aaa/aa.jpg" that your RenameTo is relative path "aa.jpg", just for measure try absolute path "/stores/1/items/aaa/aa.jpg".
 

mrd777

Member
Joined
Dec 4, 2014
Messages
7
Programming Experience
1-3
John, thanks for replying.

Again was a poor choice of words. I meant to say still. I'm still stuck.

So what I ended up doing is using a DLL library that works with .net 4.0 and that worked instead.

I don't know why and still can't fix the rename file issue, even with the absolute path you suggested.

For anyone having FTP woes like me, I suggest downloading and trying System.Net.FtpClient - Home

Mr D
 
Top Bottom