FileTransfer Object
From SecureCRT
Zmodem is a file transfer protocol that touts speed and reliability. In this terminal emulation application, it provides a mechanism for secure file transfers as long as the remote machine has Zmodem support installed.
A session is a set of options that are assigned to a connection to a remote machine. These settings and options are saved under a session name and allow the user to have different preferences for different hosts.
A Zmodem command that initiates a Zmodem receive operation. The rz command can be run from the command line on a remote machine to instruct the sender that the remote machine is ready to receive data. See also: sz
Description
The FileTransfer object provides methods for performing file transfers initiated by scripts.
Syntax
Remarks
SecureCRT's
FileTransfer
object is accessed through the top-level object’s FileTransfer
property.
FileTransfer Object Properties and Methods
|
|
||
|
|
||
|
|
||
|
|
|
Description
Returns path for session download folder.
Syntax
crt.FileTransfer.DownloadFolder
Remarks
DownloadFolder is a read-only property that returns the path for the current session's download folder. Note, files downloaded with either Xmodem or Zmodem are always placed in the session's download folder. Scripts can use this property to determine the location of the downloaded files.
Example:
MsgBox "Download completed to: " & vblf & crt.FileTransfer.DownloadFolder
Description
Specifies ASCII or binary mode for Zmodem uploads.
Syntax
crt.FileTransfer.ZmodemUploadAscii = [True | False]
Remarks
ZmodemUploadAscii specifies whether files uploaded using Zmodem will be in ASCII or binary format. When ZmodemUploadAscii is set to "true", uploads will be made in ASCII. After you have run a script that sets the ZmodemUploadAscii option to true, that setting will be saved as a session option until it is changed back either by running another script that resets it to false or by changing the option in the Select Files to Send using Zmodem dialog. If no argument is specified for this property, the current value is returned.
Note: For this option to work properly, the installation of Zmodem on the remote machine must be able to convert ASCII to use the local convention for line termination.
Example:
#$language = "VBScript"
#$interface = "1.0"
Option explicit
Dim szPrompt
szPrompt = "->"
crt.screen.synchronous = True
' Zmodem ASCII uploads
crt.FileTransfer.AddToZmodemUploadList "c:\temp\File1.txt"
crt.FileTransfer.AddToZmodemUploadList "c:\temp\File2.txt"
crt.FileTransfer.AddToZmodemUploadList "c:\temp\anotherFile.txt"
' Let CRT know that we want these files to be transferred as ASCII
crt.FileTransfer.ZmodemUploadAscii = True
' Start the Zmodem upload
crt.Screen.Send "rz" & vbCR
' Wait for transfer to complete
crt.Screen.WaitForString szPrompt
' Reset ASCII flag
crt.FileTransfer.ZmodemUploadAscii = False
Description
Places file on Zmodem upload list.
Syntax
crt.FileTransfer.AddToZmodemUploadList filepath
Remarks
AddToZmodemUploadList places the specified file on a list of files that will be uploaded during the next Zmodem upload. Once one or more files have been added to the upload list, a Zmodem upload can be initiated by the script sending the appropriate command to the remote system.
Errors:
If the path provided to AddToZmodemUploadList is not a valid file, a script error is generated and the following message is displayed:
"FileTransfer.AddToZmodemUploadList: <filepath> does not exist."
Example:
crt.FileTransfer.AddToZmodemUploadList "c:\temp\File1.txt"
crt.FileTransfer.AddToZmodemUploadList "c:\temp\File2.txt"
' Start the upload of the two files...
crt.Screen.Send "rz" & vbCR
Description
Sends specified file.
Syntax
crt.FileTransfer.SendXmodem filepath
Remarks
SendXmodem sends the specified file using the Xmodem protocol. The full path to the file must be specified. Note, the appropriate Xmodem receive command should be sent or initiated on the remote system before executing SendXmodem for the transfer to begin properly.
Errors:
1. If the SendXmodem method is executed while not connected the following script error is generated:
"FileTransfer.SendXmodem: not connected"
2. If the path provided to SendXmodem is not a valid file then a script error is generated and the following message is displayed:
"FileTransfer.SendXmodem: <filepath> does not exist."
Example:
' upload C:\temp\myFile.txt using Xmodem
crt.Screen.Send "rxmyFile.txt" & vbCR
crt.Screen.WaitForString "ready to receive"
crt.FileTransfer.SendXmodem "c:\temp\myFile.txt"
Description
Initiates file download to download folder.
Syntax
crt.FileTransfer.ReceiveXmodem filepath
Remarks
ReceiveXmodem initiates an Xmodem download of a file and saves the file as the specified filename in the session's download folder. Downloaded files are always placed in the session's download folder. Note, the Xmodem send command should be sent or initiated on the remote system before executing ReceiveXmodem for the transfer to proceed properly.
Errors:
1. If the ReceiveXmodem method is executed while not connected, the following script error is generated:
"FileTransfer.ReceiveXmodem: not connected"
2. If a filename passed to ReceiveXmodem is not a simple filename (i.e., if it is a path or contains path separators), the following script error will be generated:
"FileTransfer.ReceiveXmodem: Invalid filename \"%s\". Argument should not include path information."
Example:
crt.Screen.Send "sx -X myFile.txt" & vbCR
' Customize the wait string below to match output of remote Xmodem program.
crt.Screen.WaitForString "Give your local XMODEM receive command now"
crt.FileTransfer.ReceiveXmodem "yourFile.txt"