Guten Abend Community
Ich habe hier ein kleines Problem. Und zwar möchte ich auf der FTP-Seite ein Verzeichnis umbenennen. Bis jetzt bin ich zu keiner Lösung gekommen.
Andere Methoden wie Upload, Download, Delete etc, habe ich problemlos hingekriegt. Nur bei der Rename funkst das nicht.
Ich geh folgendermassen vor.
[highlight=vbnet]
Private Sub ftpRenameDirectory()
Dim oldName As String = "ftp://ftpPath/oldDirName"
Dim newName As String = "newDirName" 'Nur den DirNamen ohne ftpPath?
If FtpMethode.RenameDirectory(oldName, newName) Then
Stop
End If
End Sub
[/highlight]
[highlight=vbnet]
Public Class FtpMethode
Public Shared Function RenameDirectory(ByVal oldName As String, ByVal newName As String) As Boolean
Dim ftp As FtpWebRequest = Nothing, ftpStream As Stream = Nothing, ftpResponse As FtpWebResponse = Nothing
RenameDirectory = False
Try
ftp = CType(FtpWebRequest.Create(New Uri(oldName)), FtpWebRequest)
With ftp
.Credentials = New NetworkCredential("user", "pw")
.Method = WebRequestMethods.Ftp.Rename
.UseBinary = False
.KeepAlive = False
.Proxy = Nothing
.RenameTo = newName
End With
ftpResponse = CType(ftp.GetResponse(), FtpWebResponse)
ftpStream = ftpResponse.GetResponseStream()
Return True
Catch ex As Exception
MessageBox.Show(ex.Message)
Return False
Finally
If ftp IsNot Nothing Then ftp.Abort() : ftp = Nothing
If ftpStream IsNot Nothing Then ftpStream.Close()
If ftpResponse IsNot Nothing Then ftpResponse.Close()
End Try
End Function
End Class
[/highlight]
Als Fehlermeldung wird mir "Der angeforderte URI ist für diesen FTP-Befehl ungültig."
Danke für die Hilfe
Freundliche Grüsse
exc-jdbi
Ich habe hier ein kleines Problem. Und zwar möchte ich auf der FTP-Seite ein Verzeichnis umbenennen. Bis jetzt bin ich zu keiner Lösung gekommen.
Andere Methoden wie Upload, Download, Delete etc, habe ich problemlos hingekriegt. Nur bei der Rename funkst das nicht.
Ich geh folgendermassen vor.
[highlight=vbnet]
Private Sub ftpRenameDirectory()
Dim oldName As String = "ftp://ftpPath/oldDirName"
Dim newName As String = "newDirName" 'Nur den DirNamen ohne ftpPath?
If FtpMethode.RenameDirectory(oldName, newName) Then
Stop
End If
End Sub
[/highlight]
[highlight=vbnet]
Public Class FtpMethode
Public Shared Function RenameDirectory(ByVal oldName As String, ByVal newName As String) As Boolean
Dim ftp As FtpWebRequest = Nothing, ftpStream As Stream = Nothing, ftpResponse As FtpWebResponse = Nothing
RenameDirectory = False
Try
ftp = CType(FtpWebRequest.Create(New Uri(oldName)), FtpWebRequest)
With ftp
.Credentials = New NetworkCredential("user", "pw")
.Method = WebRequestMethods.Ftp.Rename
.UseBinary = False
.KeepAlive = False
.Proxy = Nothing
.RenameTo = newName
End With
ftpResponse = CType(ftp.GetResponse(), FtpWebResponse)
ftpStream = ftpResponse.GetResponseStream()
Return True
Catch ex As Exception
MessageBox.Show(ex.Message)
Return False
Finally
If ftp IsNot Nothing Then ftp.Abort() : ftp = Nothing
If ftpStream IsNot Nothing Then ftpStream.Close()
If ftpResponse IsNot Nothing Then ftpResponse.Close()
End Try
End Function
End Class
[/highlight]
Als Fehlermeldung wird mir "Der angeforderte URI ist für diesen FTP-Befehl ungültig."
Danke für die Hilfe
Freundliche Grüsse
exc-jdbi
Comment