Hack Forums
[.NET] Upload file to ftp server in vbs - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Upload file to ftp server in vbs (/showthread.php?tid=5467838)



Upload file to ftp server in vbs - DaRk LoRd FlArE - Nov 18, 2016

Source:

Set oShell = CreateObject("Shell.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Path to file or folder to upload
path = "C:\Users\%USERPROFILE%\Documents\filetoupload.txt"
FTPUpload(path)
Sub FTPUpload(path)
On Error Resume Next
'Copy Options: 16 = Yes to All
Const copyType = 16
'FTP Wait Time in ms
waitTime = 80000
FTPUser = "USERNAME"
FTPPass = "PASSWORD"
FTPHost = "FTPSERVER"
FTPDir = "/folder on ftp server to upload to"
strFTP = "ftp://" & FTPUser & ":" & FTPPass & "@" & FTPHost & FTPDir
Set objFTP = oShell.NameSpace(strFTP)
'Make new folder on FTP site
'objFTP.NewFolder "FTP Backup"
'Upload single file
If objFSO.FileExists(path) Then
Set objFile = objFSO.getFile(path)
strParent = objFile.ParentFolder
Set objFolder = oShell.NameSpace(strParent)
Set objItem = objFolder.ParseName(objFile.Name)
objFTP.CopyHere objItem, copyType
End If
'Upload all files in folder
If objFSO.FolderExists(path) Then
'Code below can be used to upload entire folder
Set objFolder = oShell.NameSpace(path)
objFTP.CopyHere objFolder.Items, copyType
End If
If Err.Number <> 0 Then
Wscript.Echo "Error: " & Err.Description
End If
'Wait for upload
WScript.Sleep waitTime
End Sub

Edit the values in green

Source/s Jacob, my friend and helper


* - Icoderz - Nov 21, 2016

thanks for share ! Good Job


* - DaRk LoRd FlArE - Nov 21, 2016

(Nov 21, 2016 02:40 AM)Icoderz Wrote:  thanks for share ! Good Job
Thanks :)