hangtime4ever
I own SmartFTP Premium. I've created a working script to upload files, from the FTP Library examples. Problem is it stops working after several weeks go by (connect error=17). Poking around the forum, it appears I may be running into a trial issue with the SmartFTP Library.
I originally had SmartFTP FTP Library 2.0.44.0, then about a month went by and I started getting the connect error=17.
I downloaded the latest version today - SmartFTP FTP Library 2.0.62.0 - and my script is working again. I suspect it will expire in 30 days - maybe?
What do I change in my script, so that my SmartFTP license is used rather than the Library license.
Here is my script in it's entirety (of course with private stuff left out):
<?xml version="1.0"?>
<package>
<job>
<reference object="sfFTPLib.SFTPConnection"/>
<reference object="sfFTPLib.SSHConnection"/>
<script language="VBScript">
<![CDATA[
'///////////////////////////////////////////////////////////////////////////////////
'//
'// Upload Web files
'//
'// Purpose:
'// - Upload Master files to the Web Site
'//
'//
'///////////////////////////////////////////////////////////////////////////////////
Dim obj
Set obj = CreateObject("sfFTPLib.SSHConnection")
WScript.Echo "SFTPConnection object created." & vbCrLf
' Settings
obj.Host = "myhost"
obj.Username = "myusername"
obj.Password = "mypassword"
obj.Port = 22
Dim strTargetPath
strTargetPath = "mytargetpath"
Dim strSourceFolder
strSourceFolder = "mysourcepath"
' Enable logging
obj.LogFile.File = "Simple.log"
Dim ret
WScript.Echo obj.Host & vbCrLf
ret = obj.Connect()
If ret = ftpErrorSuccess Then
WScript.Echo "Connect() successful. Host=" & obj.Host & vbCrLf
Dim objSFTP
Set objSFTP = obj.CreateSFTPConnection()
If objSFTP.Connect() = 0 Then
' Local Wizard Directory Listing and Upload
Dim fso, files, folder, fileList
Set fso = CreateObject("Scripting.FileSystemObject")
Set fileList = fso.CreateTextFile(".\FileList.txt", True)
Set folder = fso.GetFolder(strSourceFolder)
Set files = folder.Files
For each folderIdx In files
fileList.WriteLine(folderIdx.Name)
' Uploading a file
strRemoteFile = strTargetPath & "/" & folderIdx.Name
strLocalFile = strSourceFolder & "\" & folderIdx.Name
If objSFTP.UploadFile(strLocalFile, strRemoteFile, 0,0, 0,0) = ftpErrorSuccess Then
'WScript.Echo """" & strLocalFile & """ successfully uploaded to """ & strRemoteFile & """" & vbCrLf
Else
WScript.Echo "Failed to upload """ & strLocalFile & """ to """ & strRemoteFile & """" & vbCrLf
End If
Next
fileList.Close
WScript.Echo "Upload complete to " & obj.Host & vbCrLf
End If
Else
WScript.Echo "Connect() failed. Error = " & ret & vbCrLf
End If
]]>
</script>
</job>
</package>
I originally had SmartFTP FTP Library 2.0.44.0, then about a month went by and I started getting the connect error=17.
I downloaded the latest version today - SmartFTP FTP Library 2.0.62.0 - and my script is working again. I suspect it will expire in 30 days - maybe?
What do I change in my script, so that my SmartFTP license is used rather than the Library license.
Here is my script in it's entirety (of course with private stuff left out):
<?xml version="1.0"?>
<package>
<job>
<reference object="sfFTPLib.SFTPConnection"/>
<reference object="sfFTPLib.SSHConnection"/>
<script language="VBScript">
<![CDATA[
'///////////////////////////////////////////////////////////////////////////////////
'//
'// Upload Web files
'//
'// Purpose:
'// - Upload Master files to the Web Site
'//
'//
'///////////////////////////////////////////////////////////////////////////////////
Dim obj
Set obj = CreateObject("sfFTPLib.SSHConnection")
WScript.Echo "SFTPConnection object created." & vbCrLf
' Settings
obj.Host = "myhost"
obj.Username = "myusername"
obj.Password = "mypassword"
obj.Port = 22
Dim strTargetPath
strTargetPath = "mytargetpath"
Dim strSourceFolder
strSourceFolder = "mysourcepath"
' Enable logging
obj.LogFile.File = "Simple.log"
Dim ret
WScript.Echo obj.Host & vbCrLf
ret = obj.Connect()
If ret = ftpErrorSuccess Then
WScript.Echo "Connect() successful. Host=" & obj.Host & vbCrLf
Dim objSFTP
Set objSFTP = obj.CreateSFTPConnection()
If objSFTP.Connect() = 0 Then
' Local Wizard Directory Listing and Upload
Dim fso, files, folder, fileList
Set fso = CreateObject("Scripting.FileSystemObject")
Set fileList = fso.CreateTextFile(".\FileList.txt", True)
Set folder = fso.GetFolder(strSourceFolder)
Set files = folder.Files
For each folderIdx In files
fileList.WriteLine(folderIdx.Name)
' Uploading a file
strRemoteFile = strTargetPath & "/" & folderIdx.Name
strLocalFile = strSourceFolder & "\" & folderIdx.Name
If objSFTP.UploadFile(strLocalFile, strRemoteFile, 0,0, 0,0) = ftpErrorSuccess Then
'WScript.Echo """" & strLocalFile & """ successfully uploaded to """ & strRemoteFile & """" & vbCrLf
Else
WScript.Echo "Failed to upload """ & strLocalFile & """ to """ & strRemoteFile & """" & vbCrLf
End If
Next
fileList.Close
WScript.Echo "Upload complete to " & obj.Host & vbCrLf
End If
Else
WScript.Echo "Connect() failed. Error = " & ret & vbCrLf
End If
]]>
</script>
</job>
</package>