[AccessD] I ask Bard to write an FTP upload module

Rocky Smolin rockysmolin2 at gmail.com
Tue Apr 25 13:59:53 CDT 2023


Would this work?

'Declare variables Dim oFSO As Object Dim oFSO2 As Object Dim oFSO3 As
Object Dim sServer As String Dim sUsername As String Dim sPassword As
String Dim sLocalFile As String Dim sRemoteFile As String 'Set variables
sServer = "ftp.example.com" sUsername = "username" sPassword = "password"
sLocalFile = "C:\Documents and Settings\user\Desktop\document.txt"
sRemoteFile = "/path/to/document.txt" 'Create a new instance of the
FileSystemObject Set oFSO = CreateObject("Scripting.FileSystemObject")
'Create a new instance of the TextStream object Set oFSO2 =
oFSO.CreateTextFile(sLocalFile) 'Read the contents of the local file
oFSO2.ReadAll 'Create a new instance of the FTP object Set oFSO3 =
CreateObject("Ftp") 'Open a connection to the server oFSO3.Open sServer,
sUsername, sPassword 'Put the contents of the local file on the server
oFSO3.PutFile sLocalFile, sRemoteFile 'Close the connection oFSO3.Close
'Dispose of the objects Set oFSO = Nothing Set oFSO2 = Nothing Set oFSO3 =
Nothing End Sub

r

On Tue, Apr 25, 2023 at 11:44 AM Jim Dettman via AccessD <
accessd at databaseadvisors.com> wrote:

> No, because it is off the beaten path.
>
> There is no .FTP method in the FileSystemObject.
>
> Jim.
>
> -----Original Message-----
> From: AccessD On Behalf Of Rocky Smolin
> Sent: Tuesday, April 25, 2023 11:27 AM
> To: Access Developers discussion and problem solving
> <accessd at databaseadvisors.com>
> Subject: [AccessD] I ask Bard to write an FTP upload module
>
> I got a popup in Edge - Bear is ready to write code for me.  So I
> thought I'd give it a try with the FTP Upload program I'm trying to write.
> Said "write a module in VBA to FTP a file to a server"
>
> Below is the original code and my modifications to pick up the arguments
> from a table.
>
> It errors out on the line  Set oFTP = CreateObject("FSO.Ftp") 429 - ActiveX
> component cannot create object.
>
> The code looks pretty simple, straightforward. Is there a simple,
> straightforward fix for this?
>
> MTIA
>
> Rocky
>
>
> Here's the code that Bard created:
>
> ' Original Code
> 'Declare variables
> 'Dim oFSO As Object
> 'Dim oFTP As Object
> 'Dim strServer As String
> 'Dim strUserName As String
> 'Dim strPassword As String
> 'Dim strLocalFile As String
> 'Dim strRemoteFile As String
>
> 'Set variables
> 'strServer = "myserver.example.com"
> 'strUserName = "username"
> 'strPassword = "password"
> 'strLocalFile = "C:\Users\YourUserName\Desktop\myfile.txt"
> 'strRemoteFile = "/myfolder/myfile.txt"
>
> 'Create an instance of the FileSystemObject
> 'Set oFSO = CreateObject("Scripting.FileSystemObject")
>
> 'Create an instance of the FTP object
> 'Set oFTP = CreateObject("FSO.Ftp")
>
> 'Open a connection to the FTP server
> 'oFTP.Open strServer, strUserName, strPassword
>
> 'Upload the file
> 'oFTP.PutFile strLocalFile, strRemoteFile
>
> 'Close the connection
> 'oFTP.Close
>
> And here's the code I modified to pick up the arguments from a table:
>
> 'Dim oFSO As Object
> 'Dim oFTP As Object
> 'Dim strServer As String
> 'Dim strUserName As String
> 'Dim strPassword As String
> 'Dim strLocalFile As String
> 'Dim strRemoteFile As String
>
> 'Set variables
> 'strServer = Me.fldHost
> 'strUserName = Me.fldUser
> 'strPassword = Me.fldPassword
> 'strLocalFile = Me.fldFileToUpload
> 'strRemoteFile = Me.fldDestinationDirectory & Me.fldDestinationFileName
>
> 'Create an instance of the FileSystemObject
> 'Set oFSO = CreateObject("Scripting.FileSystemObject") '
>
> 'Create an instance of the FTP object
> 'Set oFTP = CreateObject("FSO.Ftp")
>
> 'Open a connection to the FTP server
> 'oFSO.Open strServer, strUserName, strPassword
>
> 'Upload the file
> 'oFTP.PutFile strLocalFile, strRemoteFile
>
> 'Close the connection
> 'oFTP.Close
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>


More information about the AccessD mailing list