Sending data through FTP
Sometimes, our client may ask us to upload a datafile on the FTP server. We can use the Windows built-in client to develop our FTP upload program.
Getting ready
Make sure we have an active FTP server and logon credentials.
How to do it...
Let's start by creating a new codeunit from Object Designer.
Add a function name
FTP
that takes in the following parameters:Name
DataType
Length
UserName
Text
50
Password
Text
50
ServerName
Text
50
FileToMove
Text
250
Then add the following local variables to the function:
Name
Type
Length
BatchFileName
Text
250
BatchFile
File
BatchfileStream
OutStream
BatchFileData
Text
250
Now add the following code to the function:
BatchFileData := 'D:\Temp\navFTP.dat'; BatchFileName := 'D:\Temp\navFTP.bat'; BatchFile.CREATE(BatchFileName); BatchFile.CREATEOUTSTREAM(BatchfileStream); BatchfileStream.WRITETEXT('@echo off'); BatchfileStream.WRITETEXT; BatchfileStream.WRITETEXT('echo user ' +UserName + ' >> ' + BatchFileData...