Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

move file on ftp server 1

Status
Not open for further replies.

DevelopV

Technical User
Mar 16, 2012
113
ZA
How can I move a file from one folder to another on an ftp server?
 
In the FTP client session:
cd onefolder
ren file /path/to/anotherfolder/file

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
BTW, I've already replied here:
thread705-1704041
 
Do you have this as a function? like FTPGet
 
check out this..


It has all the FTP commands available via WinINet.dll, not sure though if you can use paths along with file name to move the file?

Never done it, so roll your own function and share with us, would be good to know.

Here is the definition of the FtpRenameFile function...


"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
oh and don't forget to delare the API function in the FTP module ;-)

Code:
Private Declare Function FtpRenameFile Lib "wininet.dll" Alias "FtpRenameFileA" _
    (ByVal hFtpSession As Long, ByVal lpszExisting As String, ByVal lpszNew As String) As Boolean

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
Here we go!
Code:
Private Declare Function FtpRenameFile Lib "wininet.dll" Alias "FtpRenameFileA" _
    (ByVal hFtpSession As Long, ByVal lpszExisting As String, ByVal lpszNew As String) As Boolean

Code:
Function FTPRename(ByVal HostName As String, _
                    ByVal UserName As String, _
                    ByVal Password As String, _
                    ByVal ExistingFileName As String, _
                    ByVal NewFileName As String) As Boolean

On Error GoTo Err_Function

' Declare variables
Dim hConnection, hOpen, hFile  As Long ' Used For Handles


' Open Internet Connecion
hOpen = InternetOpen("FTP", 1, "", vbNullString, 0)

' Connect to FTP
hConnection = InternetConnect(hOpen, HostName, INTERNET_DEFAULT_FTP_PORT, UserName, Password, INTERNET_SERVICE_FTP, IIf(PassiveConnection, INTERNET_FLAG_PASSIVE, 0), 0)

' Change Directory
'Call FtpSetCurrentDirectory(hConnection, sDir)

' Open Remote File
Call FTPRenameFile(hConnection, ExistingFileName, NewFileName)

' Close Internet Connection
Call InternetCloseHandle(hOpen)
Call InternetCloseHandle(hConnection)

FTPRename = True

Exit Function

Err_Function:
MsgBox "Error in FTPRename : " & Err.Description
Exit Function

End Function
Code:
FTPRename InternetDomainName, UserName, Password, Existing File Name Inclunding Path , Existing File Name Inclunding Path
 
I would change this...
Code:
Call FTPRenameFile(hConnection, ExistingFileName, NewFileName)

FTPRename = True

To this ...
Code:
FTPRename = FTPRenameFile(hConnection, ExistingFileName, NewFileName)

Remember the API function returns boolean regarding success so use that to set function variable so your calling code knows if it was succesfull.

Currently you are returning true regardless!


"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top