FTP: Difference between revisions

20 bytes added ,  5 months ago
m
(Added FreeBasic)
m (→‎{{header|Wren}}: Minor tidy)
 
(One intermediate revision by one other user not shown)
Line 5:
<br/><br/>
 
=={{header|BaConBASIC}}==
==={{header|BaCon}}===
Using libCURL.
<syntaxhighlight lang="bacon">OPTION PARSE FALSE
Line 72 ⟶ 73:
 
CLOSE NETWORK ftp</syntaxhighlight>
 
 
==={{header|FreeBASIC}}===
Original code programmed by PaulSquires
[https://www.freebasic.net/forum/viewtopic.php?f=7&t=23867]
{{libheader|clsFTP}}
{{works with|Windows}}
====clsFTP.bas====
<syntaxhighlight lang="vb">''
''
'' FTP class (Public Domain code - enjoy).
'' Windows only. Uses WinInet system functions.
'' Paul Squires of PlanetSquires Software (August 2015)
''
'' Compiler: FreeBASIC 1.03 (32-bit) (64-bit)
''
 
#Include Once "windows.bi"
#Include Once "\win\wininet.bi"
 
' //
' //
' //
Type clsFTP
Private:
m_hSession As HINTERNET
m_hConnection As HINTERNET
m_LastError As Integer
m_ServerPort As Integer
m_ServerName As String
m_UserName As String
m_Password As String
Public:
Declare Constructor
Declare Destructor
Declare Property hSession() As HINTERNET
Declare Property hSession(Byval nValue As HINTERNET)
Declare Property hConnection() As HINTERNET
Declare Property hConnection(Byval nValue As HINTERNET)
Declare Property LastError() As Integer
Declare Property ServerPort(Byval nValue As Integer)
Declare Property ServerPort() As Integer
Declare Property LastError(Byval nValue As Integer)
Declare Property ServerName() As String
Declare Property ServerName(Byval sValue As String)
Declare Property UserName() As String
Declare Property UserName(Byval sValue As String)
Declare Property Password() As String
Declare Property Password(Byval sValue As String)
Declare Function Connect Overload() As WINBOOL
Declare Function Connect Overload(Byval sServerName As String, _
Byval sServerPort As Integer, _
Byval sUserName As String, _
Byval sPassword As String) As WINBOOL
Declare Sub Disconnect()
Declare Function SetCurrentFolder(Byval sFolderName As String) As WINBOOL
Declare Function GetCurrentFolder() As String
Declare Function RenameFile(Byval sOldFilename As String, _
Byval sNewFilename As String) As WINBOOL
Declare Function UploadFile(Byval sLocal As String, _
Byval sRemote As String) As WINBOOL
Declare Function DownloadFile(Byval sLocal As String, _
Byval sRemote As String) As WINBOOL
Declare Function KillFile(Byval sRemote As String) As WINBOOL
End Type
 
 
''
'' Initialize the class
''
Constructor clsFTP
m_ServerPort = INTERNET_DEFAULT_FTP_PORT ' port 21
End Constructor
 
 
''
'' Close any open connection and session
''
Destructor clsFTP
this.Disconnect
End Destructor
 
 
''
'' hSession (Property)
''
Property clsFTP.hSession() As HINTERNET
Property = this.m_hSession
End Property
 
Property clsFTp.hSession(Byval nValue As HINTERNET)
this.m_hSession = nValue
End Property
 
 
''
'' hConnection (Property)
''
Property clsFTP.hConnection() As HINTERNET
Property = this.m_hConnection
End Property
 
Property clsFTp.hConnection(Byval nValue As HINTERNET)
this.m_hConnection = nValue
End Property
 
 
''
'' LastError (Property)
''
Property clsFTP.LastError() As Integer
Property = this.m_LastError
End Property
 
Property clsFTp.LastError(Byval nValue As Integer)
this.m_LastError = nValue
End Property
 
 
''
'' ServerPort (Property)
''
Property clsFTP.ServerPort() As Integer
Property = this.m_ServerPort
End Property
 
Property clsFTp.ServerPort(Byval nValue As Integer)
this.m_ServerPort = nValue
End Property
 
 
''
'' ServerName (Property)
''
Property clsFTP.ServerName() As String
Property = this.m_ServerName
End Property
 
Property clsFTp.ServerName(Byval sValue As String)
this.m_ServerName = sValue
End Property
 
 
''
'' UserName (Property)
''
Property clsFTP.UserName() As String
Property = this.m_UserName
End Property
 
Property clsFTp.UserName(Byval sValue As String)
this.m_UserName = sValue
End Property
 
 
''
'' Password (Property)
''
Property clsFTP.Password() As String
Property = this.m_Password
End Property
 
Property clsFTp.Password(Byval sValue As String)
this.m_Password = sValue
End Property
 
 
''
'' Close current connection and end session
''
Sub clsFTP.Disconnect()
InternetCloseHandle this.hConnection
InternetCloseHandle this.hSession
this.hConnection = 0: this.hSession = 0
End Sub
 
 
''
'' Connect to an ftp host (overload). Returns TRUE if successful.
''
Function clsFTP.Connect Overload() As WINBOOL
this.hSession = InternetOpen("ftpClass", INTERNET_OPEN_TYPE_DIRECT, "", "", 0)
If this.hSession = 0 Then
this.LastError = GetLastError
Function = False: Exit Function
End If
this.hConnection = InternetConnect(_
this.hSession, this.ServerName, this.ServerPort, _
this.UserName, this.Password, _
INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0)
If this.hConnection = 0 Then
this.LastError = GetLastError
InternetCloseHandle(this.hSession)
Function = False: Exit Function
End If
Function = True
End Function
 
 
''
'' Connect to an ftp host (overload). Returns TRUE if successful.
''
Function clsFTP.Connect Overload (Byval sServerName As String, _
Byval nServerPort As Integer, _
Byval sUserName As String, _
Byval sPassword As String) As WINBOOL
this.ServerName = sServerName
this.ServerPort = nServerPort
this.UserName = sUserName
this.Password = sPassword
Function = this.Connect
End Function
 
 
''
'' Change to a folder on the server. Returns TRUE if successful.
''
Function clsFTP.SetCurrentFolder(Byval sFolderName As String) As WINBOOL
Function = FtpSetCurrentDirectory(this.hConnection, sFolderName)
this.LastError = GetLastError
End Function
 
 
''
'' Retrieves the name of current folder on the server.
''
Function clsFTP.GetCurrentFolder() As String
Dim zBuffer As ZString * MAX_PATH
Dim nLength As Integer = MAX_PATH
FtpGetCurrentDirectory(this.hConnection, zBuffer, Cast(LPDWORD, @nLength))
this.LastError = GetLastError
Function = zBuffer
End Function
 
 
''
'' Rename a file on the server. Returns TRUE if successful.
''
Function clsFTP.RenameFile(Byval sOldFilename As String, Byval sNewFilename As String) As WINBOOL
Function = FtpRenameFile(this.hConnection, sOldFilename, sNewFilename)
this.LastError = GetLastError
End Function
 
 
''
'' Upload a file to the server. Returns TRUE if successful.
''
Function clsFTP.UploadFile(Byval sLocal As String, Byval sRemote As String) As WINBOOL
Function = FtpPutFile(this.hConnection, sLocal, sRemote, FTP_TRANSFER_TYPE_BINARY, 0)
this.LastError = GetLastError
End Function
 
 
''
'' Download a file from the server. Returns TRUE if successful.
''
Function clsFTP.DownloadFile(Byval sLocal As String, Byval sRemote As String) As WINBOOL
Function = FtpGetFile(this.hConnection, sRemote, sLocal, False, _
FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_BINARY Or INTERNET_FLAG_RELOAD, 0)
this.LastError = GetLastError
End Function
 
 
''
'' Remove a file from the server. Returns TRUE if successful.
''
Function clsFTP.KillFile(Byval sRemote As String) As WINBOOL
Function = FtpDeleteFile(this.hConnection, sRemote)
this.LastError = GetLastError
End Function</syntaxhighlight>
 
====simple_test.bas====
<syntaxhighlight lang="vb">#Include Once "windows.bi"
#Include Once "clsFTP.bas"
 
Dim ftp As clsFTP
 
If ftp.Connect("ftp.ed.ac.uk", 21, "anonymous", "aaa@gmail.com") = False Then
Print "Error connecting to server. LastError = "; ftp.LastError
End If
 
If ftp.SetCurrentFolder("pub/courses") = False Then
Print "Error setting current folder. LastError = "; ftp.LastError
End If
 
Print "Current folder = "; ftp.GetCurrentFolder()
 
If ftp.DownloadFile("make.notes.tar", "make.notes.tar") = False Then
Print "Error downloading file. LastError = "; ftp.LastError
End If
 
ftp.Disconnect
 
Print "Done."
 
Sleep</syntaxhighlight>
 
==={{header|FutureBasic}}===
FB for Mac easily interfaces with the terminal command line. NOTE: The curl command line tool used in this example offers upload and sending capabilities. It supports FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS, FILE, POP3, IMAP, SMTP, RTMP and RTSP.
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
#plist NSAppTransportSecurity @{NSAllowsArbitraryLoads:YES}
 
local fn RunTerminalCommand( cmd as CFStringRef ) as CFStringRef
CFStringRef outputStr = NULL
TaskRef task = fn TaskInit
TaskSetExecutableURL( task, fn URLFileURLWithPath( @"/bin/zsh" ) )
CFStringRef cmdStr = fn StringWithFormat( @"%@", cmd )
CFArrayRef args = fn ArrayWithObjects( @"-c", cmdStr, NULL )
TaskSetArguments( task, args )
PipeRef p = fn PipeInit
TaskSetStandardOutput( task, p )
TaskSetStandardError( task, p )
FileHandleRef fh = fn PipeFileHandleForReading( p )
fn TaskLaunch( task, NULL )
TaskWaitUntilExit( task )
ErrorRef err
CFDataRef dta = fn FileHandleReadDataToEndOfFile( fh, @err )
if err then NSLog( @"%@", fn ErrorLocalizedDescription( err ) ) : exit fn
outputStr = fn StringWithData( dta, NSUTF8StringEncoding )
end fn = outputStr
 
NSLog( @"%@", fn RunTerminalCommand( @"curl ftp://ftp.slackware.com/welcome.msg" ) )
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre style="font-size: 12px">
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
 
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 754 100 754 0 0 1363 0 --:--:-- --:--:-- --:--:-- 1361
 
---------------------------------------------------------------------------
R S Y N C . O S U O S L . O R G
Oregon State University
Open Source Lab
 
Unauthorized use is prohibited - violators will be prosecuted
---------------------------------------------------------------------------
 
For more information about the OSL visit:
http://osuosl.org/services/hosting
 
This host is the home to the primary archives of several
projects. We would prefer that only primary/secondary
mirrors use this service. Thanks!
 
---------------------------------------------------------------------------
</pre>
 
=={{header|Go}}==
Using the FTP package from [https://godoc.org/github.com/stacktic/ftp github.com/stacktic/ftp].
<syntaxhighlight lang="go">package main
 
import (
"fmt"
"io"
"log"
"os"
 
"github.com/stacktic/ftp"
)
 
func main() {
// Hard-coded demonstration values
const (
hostport = "localhost:21"
username = "anonymous"
password = "anonymous"
dir = "pub"
file = "somefile.bin"
)
 
conn, err := ftp.Connect(hostport)
if err != nil {
log.Fatal(err)
}
defer conn.Quit()
fmt.Println(conn)
 
if err = conn.Login(username, password); err != nil {
log.Fatal(err)
}
if err = conn.ChangeDir(dir); err != nil {
log.Fatal(err)
}
fmt.Println(conn.CurrentDir())
files, err := conn.List(".")
if err != nil {
log.Fatal(err)
}
for _, f := range files {
fmt.Printf("%v %12d %v %v\n", f.Time, f.Size, f.Type, f.Name)
}
 
r, err := conn.Retr(file)
if err != nil {
log.Fatal(err)
}
defer r.Close()
 
f, err := os.Create(file)
if err != nil {
log.Fatal(err)
}
defer f.Close()
 
n, err := io.Copy(f, r)
if err != nil {
log.Fatal(err)
}
 
fmt.Println("Wrote", n, "bytes to", file)
}</syntaxhighlight>
 
=={{header|Batch File}}==
Line 609 ⟶ 1,040:
ftp:close(Pid).
</syntaxhighlight>
 
=={{header|FreeBASIC}}==
Original code programmed by PaulSquires
[https://www.freebasic.net/forum/viewtopic.php?f=7&t=23867]
{{libheader|clsFTP}}
{{works with|Windows}}
====clsFTP.bas====
<syntaxhighlight lang="vb">''
''
'' FTP class (Public Domain code - enjoy).
'' Windows only. Uses WinInet system functions.
'' Paul Squires of PlanetSquires Software (August 2015)
''
'' Compiler: FreeBASIC 1.03 (32-bit) (64-bit)
''
 
#Include Once "windows.bi"
#Include Once "\win\wininet.bi"
 
' //
' //
' //
Type clsFTP
Private:
m_hSession As HINTERNET
m_hConnection As HINTERNET
m_LastError As Integer
m_ServerPort As Integer
m_ServerName As String
m_UserName As String
m_Password As String
Public:
Declare Constructor
Declare Destructor
Declare Property hSession() As HINTERNET
Declare Property hSession(Byval nValue As HINTERNET)
Declare Property hConnection() As HINTERNET
Declare Property hConnection(Byval nValue As HINTERNET)
Declare Property LastError() As Integer
Declare Property ServerPort(Byval nValue As Integer)
Declare Property ServerPort() As Integer
Declare Property LastError(Byval nValue As Integer)
Declare Property ServerName() As String
Declare Property ServerName(Byval sValue As String)
Declare Property UserName() As String
Declare Property UserName(Byval sValue As String)
Declare Property Password() As String
Declare Property Password(Byval sValue As String)
Declare Function Connect Overload() As WINBOOL
Declare Function Connect Overload(Byval sServerName As String, _
Byval sServerPort As Integer, _
Byval sUserName As String, _
Byval sPassword As String) As WINBOOL
Declare Sub Disconnect()
Declare Function SetCurrentFolder(Byval sFolderName As String) As WINBOOL
Declare Function GetCurrentFolder() As String
Declare Function RenameFile(Byval sOldFilename As String, _
Byval sNewFilename As String) As WINBOOL
Declare Function UploadFile(Byval sLocal As String, _
Byval sRemote As String) As WINBOOL
Declare Function DownloadFile(Byval sLocal As String, _
Byval sRemote As String) As WINBOOL
Declare Function KillFile(Byval sRemote As String) As WINBOOL
End Type
 
 
''
'' Initialize the class
''
Constructor clsFTP
m_ServerPort = INTERNET_DEFAULT_FTP_PORT ' port 21
End Constructor
 
 
''
'' Close any open connection and session
''
Destructor clsFTP
this.Disconnect
End Destructor
 
 
''
'' hSession (Property)
''
Property clsFTP.hSession() As HINTERNET
Property = this.m_hSession
End Property
 
Property clsFTp.hSession(Byval nValue As HINTERNET)
this.m_hSession = nValue
End Property
 
 
''
'' hConnection (Property)
''
Property clsFTP.hConnection() As HINTERNET
Property = this.m_hConnection
End Property
 
Property clsFTp.hConnection(Byval nValue As HINTERNET)
this.m_hConnection = nValue
End Property
 
 
''
'' LastError (Property)
''
Property clsFTP.LastError() As Integer
Property = this.m_LastError
End Property
 
Property clsFTp.LastError(Byval nValue As Integer)
this.m_LastError = nValue
End Property
 
 
''
'' ServerPort (Property)
''
Property clsFTP.ServerPort() As Integer
Property = this.m_ServerPort
End Property
 
Property clsFTp.ServerPort(Byval nValue As Integer)
this.m_ServerPort = nValue
End Property
 
 
''
'' ServerName (Property)
''
Property clsFTP.ServerName() As String
Property = this.m_ServerName
End Property
 
Property clsFTp.ServerName(Byval sValue As String)
this.m_ServerName = sValue
End Property
 
 
''
'' UserName (Property)
''
Property clsFTP.UserName() As String
Property = this.m_UserName
End Property
 
Property clsFTp.UserName(Byval sValue As String)
this.m_UserName = sValue
End Property
 
 
''
'' Password (Property)
''
Property clsFTP.Password() As String
Property = this.m_Password
End Property
 
Property clsFTp.Password(Byval sValue As String)
this.m_Password = sValue
End Property
 
 
''
'' Close current connection and end session
''
Sub clsFTP.Disconnect()
InternetCloseHandle this.hConnection
InternetCloseHandle this.hSession
this.hConnection = 0: this.hSession = 0
End Sub
 
 
''
'' Connect to an ftp host (overload). Returns TRUE if successful.
''
Function clsFTP.Connect Overload() As WINBOOL
this.hSession = InternetOpen("ftpClass", INTERNET_OPEN_TYPE_DIRECT, "", "", 0)
If this.hSession = 0 Then
this.LastError = GetLastError
Function = False: Exit Function
End If
this.hConnection = InternetConnect(_
this.hSession, this.ServerName, this.ServerPort, _
this.UserName, this.Password, _
INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0)
If this.hConnection = 0 Then
this.LastError = GetLastError
InternetCloseHandle(this.hSession)
Function = False: Exit Function
End If
Function = True
End Function
 
 
''
'' Connect to an ftp host (overload). Returns TRUE if successful.
''
Function clsFTP.Connect Overload (Byval sServerName As String, _
Byval nServerPort As Integer, _
Byval sUserName As String, _
Byval sPassword As String) As WINBOOL
this.ServerName = sServerName
this.ServerPort = nServerPort
this.UserName = sUserName
this.Password = sPassword
Function = this.Connect
End Function
 
 
''
'' Change to a folder on the server. Returns TRUE if successful.
''
Function clsFTP.SetCurrentFolder(Byval sFolderName As String) As WINBOOL
Function = FtpSetCurrentDirectory(this.hConnection, sFolderName)
this.LastError = GetLastError
End Function
 
 
''
'' Retrieves the name of current folder on the server.
''
Function clsFTP.GetCurrentFolder() As String
Dim zBuffer As ZString * MAX_PATH
Dim nLength As Integer = MAX_PATH
FtpGetCurrentDirectory(this.hConnection, zBuffer, Cast(LPDWORD, @nLength))
this.LastError = GetLastError
Function = zBuffer
End Function
 
 
''
'' Rename a file on the server. Returns TRUE if successful.
''
Function clsFTP.RenameFile(Byval sOldFilename As String, Byval sNewFilename As String) As WINBOOL
Function = FtpRenameFile(this.hConnection, sOldFilename, sNewFilename)
this.LastError = GetLastError
End Function
 
 
''
'' Upload a file to the server. Returns TRUE if successful.
''
Function clsFTP.UploadFile(Byval sLocal As String, Byval sRemote As String) As WINBOOL
Function = FtpPutFile(this.hConnection, sLocal, sRemote, FTP_TRANSFER_TYPE_BINARY, 0)
this.LastError = GetLastError
End Function
 
 
''
'' Download a file from the server. Returns TRUE if successful.
''
Function clsFTP.DownloadFile(Byval sLocal As String, Byval sRemote As String) As WINBOOL
Function = FtpGetFile(this.hConnection, sRemote, sLocal, False, _
FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_BINARY Or INTERNET_FLAG_RELOAD, 0)
this.LastError = GetLastError
End Function
 
 
''
'' Remove a file from the server. Returns TRUE if successful.
''
Function clsFTP.KillFile(Byval sRemote As String) As WINBOOL
Function = FtpDeleteFile(this.hConnection, sRemote)
this.LastError = GetLastError
End Function</syntaxhighlight>
 
====simple_test.bas====
<syntaxhighlight lang="vb">#Include Once "windows.bi"
#Include Once "clsFTP.bas"
 
Dim ftp As clsFTP
 
If ftp.Connect("ftp.ed.ac.uk", 21, "anonymous", "aaa@gmail.com") = False Then
Print "Error connecting to server. LastError = "; ftp.LastError
End If
 
If ftp.SetCurrentFolder("pub/courses") = False Then
Print "Error setting current folder. LastError = "; ftp.LastError
End If
 
Print "Current folder = "; ftp.GetCurrentFolder()
 
If ftp.DownloadFile("make.notes.tar", "make.notes.tar") = False Then
Print "Error downloading file. LastError = "; ftp.LastError
End If
 
ftp.Disconnect
 
Print "Done."
 
Sleep</syntaxhighlight>
 
=={{header|FutureBasic}}==
FB for Mac easily interfaces with the terminal command line. NOTE: The curl command line tool used in this example offers upload and sending capabilities. It supports FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS, FILE, POP3, IMAP, SMTP, RTMP and RTSP.
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
#plist NSAppTransportSecurity @{NSAllowsArbitraryLoads:YES}
 
local fn RunTerminalCommand( cmd as CFStringRef ) as CFStringRef
CFStringRef outputStr = NULL
TaskRef task = fn TaskInit
TaskSetExecutableURL( task, fn URLFileURLWithPath( @"/bin/zsh" ) )
CFStringRef cmdStr = fn StringWithFormat( @"%@", cmd )
CFArrayRef args = fn ArrayWithObjects( @"-c", cmdStr, NULL )
TaskSetArguments( task, args )
PipeRef p = fn PipeInit
TaskSetStandardOutput( task, p )
TaskSetStandardError( task, p )
FileHandleRef fh = fn PipeFileHandleForReading( p )
fn TaskLaunch( task, NULL )
TaskWaitUntilExit( task )
ErrorRef err
CFDataRef dta = fn FileHandleReadDataToEndOfFile( fh, @err )
if err then NSLog( @"%@", fn ErrorLocalizedDescription( err ) ) : exit fn
outputStr = fn StringWithData( dta, NSUTF8StringEncoding )
end fn = outputStr
 
NSLog( @"%@", fn RunTerminalCommand( @"curl ftp://ftp.slackware.com/welcome.msg" ) )
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre style="font-size: 12px">
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
 
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 754 100 754 0 0 1363 0 --:--:-- --:--:-- --:--:-- 1361
 
---------------------------------------------------------------------------
R S Y N C . O S U O S L . O R G
Oregon State University
Open Source Lab
 
Unauthorized use is prohibited - violators will be prosecuted
---------------------------------------------------------------------------
 
For more information about the OSL visit:
http://osuosl.org/services/hosting
 
This host is the home to the primary archives of several
projects. We would prefer that only primary/secondary
mirrors use this service. Thanks!
 
---------------------------------------------------------------------------
</pre>
 
=={{header|Go}}==
Using the FTP package from [https://godoc.org/github.com/stacktic/ftp github.com/stacktic/ftp].
<syntaxhighlight lang="go">package main
 
import (
"fmt"
"io"
"log"
"os"
 
"github.com/stacktic/ftp"
)
 
func main() {
// Hard-coded demonstration values
const (
hostport = "localhost:21"
username = "anonymous"
password = "anonymous"
dir = "pub"
file = "somefile.bin"
)
 
conn, err := ftp.Connect(hostport)
if err != nil {
log.Fatal(err)
}
defer conn.Quit()
fmt.Println(conn)
 
if err = conn.Login(username, password); err != nil {
log.Fatal(err)
}
if err = conn.ChangeDir(dir); err != nil {
log.Fatal(err)
}
fmt.Println(conn.CurrentDir())
files, err := conn.List(".")
if err != nil {
log.Fatal(err)
}
for _, f := range files {
fmt.Printf("%v %12d %v %v\n", f.Time, f.Size, f.Type, f.Name)
}
 
r, err := conn.Retr(file)
if err != nil {
log.Fatal(err)
}
defer r.Close()
 
f, err := os.Create(file)
if err != nil {
log.Fatal(err)
}
defer f.Close()
 
n, err := io.Copy(f, r)
if err != nil {
log.Fatal(err)
}
 
fmt.Println("Wrote", n, "bytes to", file)
}</syntaxhighlight>
 
 
 
=={{header|Groovy}}==
Line 1,996:
{{libheader|ftplib}}
An embedded program so we can ask the C host to communicate with ''ftplib'' for us.
<syntaxhighlight lang="ecmascriptwren">/* ftpFTP.wren */
 
var FTPLIB_CONNMODE = 1
Line 2,163:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "ftpFTP.wren";
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
9,476

edits