Chapter 3 DynaScript Predefined Objects
The FTP
object
has these methods:
FTP.ChangeCurrentDirectory( directoryName )
Changes the current directory name on the FTP server.
Boolean.
This example creates a directory called Dynamo on the FTP server, changes to that directory, and places a file called test.doc in it:
<!--SCRIPT
ftpSession = new FTP ("ftpserv", "anonymous", "sam@sybase.com");
ftpSession.CreateDirectory("Dynamo");
ftpSession.ChangeCurrentDirectory("Dynamo");
if( !ftpSession.PutFile("test.doc", "g:\\dynamo\\ftp\\test.doc")) {
document.writeln( ftpSession.GetErrorCode() );
document.writeln( ftpSession.GetErrorInfo() );
}
-->
FTP.Connect( )
Connects to the FTP server.
This example connects to an FTP server and displays the current directory. It then disconnects and requests again to display the current directory, but no directory should be displayed. It then connects again, and once again displays the current directory:
<!--SCRIPT
ftpSession = new FTP ("ftpserv", "anonymous", "sam@sybase.com");
curdir = ftpSession.RetrieveCurrentDirectory();
document.WriteLn( "After connect " + curdir );
ftpSession.Disconnect();
curdir = ftpSession.RetrieveCurrentDirectory();
document.WriteLn( "After disconnect " + curdir );
ftpSession.Connect();
curdir = ftpSession.RetrieveCurrentDirectory();
document.WriteLn( "After connect " +curdir );
-->
FTP.CreateDirectory( directoryName )
Creates a directory on the FTP server.
Boolean.
This example creates a directory called Dynamo on the FTP server, changes to that directory, and places a file called test.doc in it:
<!--SCRIPT
ftpSession = new FTP ("ftpserv", "anonymous", "sam@sybase.com");
ftpSession.CreateDirectory("Dynamo");
ftpSession.ChangeCurrentDirectory("Dynamo");
if( !ftpSession.PutFile("test.doc", "g:\\dynamo\\ftp\\test.doc")) {
document.writeln( ftpSession.GetErrorCode() );
document.writeln( ftpSession.GetErrorInfo() );
}
-->
FTP.DeleteFile( fileName )
Deletes a file from the FTP server.
Boolean.
This example deletes the test.doc file:
<!--SCRIPT
ftpSession = new FTP ("ftpserv", "anonymous", "sam@sybase.com");
if( !ftpSession.DeleteFile( "test.doc" )) {
document.writeln( ftpSession.GetErrorCode() );
document.writeln( ftpSession.GetErrorInfo() );
}
ftpSession.Disconnect();
-->
FTP.Disconnect( )
Disconnects from the FTP server.
This example connects to an FTP server, deletes a file, then disconnects:
<!--SCRIPT
ftpSession = new FTP ( "ftpserv", "anonymous", "sam@sybase.com");
ftpSession.ChangeCurrentDirectory( "Dynamo" );
if( !ftpSession.DeleteFile( "test.doc" )) {
document.writeln( ftpSession.GetErrorCode() );
document.writeln( ftpSession.GetErrorInfo() );
}
ftpSession.Disconnect();
-->
FTP.GetErrorCode( )
Returns a code representing the most recent error. This may be either a three-digit FTP code or a three-digit code in the 900s that has been generated by Dynamo.
Integer.
This example puts a file on the FTP server and checks for errors:
<!--SCRIPT
ftpSession = new FTP ("ftpserv", "anonymous", "sam@sybase.com");
if( !ftpSession.PutFile("test.doc", "g:\\dynamo\\ftp\\test.doc")) {
document.writeln( ftpSession.GetErrorCode() );
document.writeln( ftpSession.GetErrorInfo() );
}
-->
FTP.GetErrorInfo( )
Returns a string containing an error message, either from the FTP server or from PowerDynamo.
String.
This example places a file on the FTP server and checks for errors:
<!--SCRIPT
ftpSession = new FTP ("ftpserv", "anonymous", "sam@sybase.com");
if( !ftpSession.PutFile("test.doc", "g:\\dynamo\\ftp\\test.doc")) {
document.writeln( ftpSession.GetErrorCode() );
document.writeln( ftpSession.GetErrorInfo() );
}
-->
FTP.PutData( remoteFileName, localData [,transferType, failIfRemoteFileExists] )
Stores Dynamo data to the FTP server from a local machine. The parameters are:
remoteFileName
The
name of the file on the remote machine.
localData
The
name of the data variable in your script.
transferType
Can
be one of ASCII, binary, EBCDIC, image or local. The default is
binary.
failIfRemoteFileExists
A Boolean
specifying the action to be taken if the file already exists. The
default is true.
Boolean.
This script is called from another script where
users already entered their first and last name and those values
are held in document.value.fname
and document.value.lname
.
This script sends the data in document.value.lname
to
a file called putdata.ssc on the FTP server:
<!--SCRIPT
document.writeln("The first name is " + document.value.fname);
document.writeln("The last name is " + document.value.lname);
ftpSession = new FTP ("ftpserv", "anonymous", "sam@sybase.com");
if( !ftpSession.PutData("putdata.ssc", document.value.lname)) {
document.writeln( ftpSession.GetErrorCode() );
document.writeln( ftpSession.GetErrorInfo() );
}
ftpSession.Disconnect();
-->
FTP.PutDataWithAppend( remoteFileName, localData [, transferType] )
Similar to the PutData
method
except that if the remote file already exists, the local data is
appended to the end of the file. If the remote file does not exist,
a new file is created.
remoteFileName
The
name of the file on the remote machine.
localData
The
name of the data on the local machine.
transferType
Can
be one of ASCII, binary, EBCDIC, image, or local. The default is
binary.
Boolean.
This script is called from another script where
users entered their first and last name and those values are held
in document.value.fname
and document.value.lname
.
This script appends the data in document.value.lname
to
a file called putdata.ssc on the FTP server:
<!--SCRIPT
document.writeln("The first name is " + document.value.fname);
document.writeln("The last name is " + document.value.lname);
ftpSession = new FTP ("ftpserv", "anonymous", "sam@sybase.com");
if( !ftpSession.PutDataWithAppend("putdata.ssc", document.value.lname)) {
document.writeln( ftpSession.GetErrorCode() );
document.writeln( ftpSession.GetErrorInfo() );
}
ftpSession.Disconnect();
-->
FTP.PutDocument( remoteFileName, documentName [, transferType ] )
Copies a Dynamo Web site document to an FTP server. The parameters are:
remoteFileName
The
name of the file on the remote machine.
documentName
The
name of the PowerDynamo document on the local machine.
transferType
Can
be one of ASCII, binary, EBCDIC, image or local. The default is
binary.
Boolean.
This example puts the Dynamo script test.ssc on the FTP server:
<!--SCRIPT
ftpSession = new FTP ("ftpserv", "anonymous", "sam@sybase.com");
if( !ftpSession.PutDocument("test.ssc", "test.ssc")) {
document.writeln( ftpSession.GetErrorCode() );
document.writeln( ftpSession.GetErrorInfo() );
}
ftpSession.Disconnect();
-->
FTP.PutDocumentWithAppend( remoteFileName, documentName [, tranferType, failIfRemoteFileExists] )
Similar to the PutData
method
except that if the remote file already exists on the remote machine
the Dynamo document is appended to the end. If the remote file does
not exist, a new file is created. The parameters are:
remoteFileName
The
name of the file on the remote machine.
documentName
The
name of the PowerDynamo document on the local machine.
transferType
Can
be one of ASCII, binary, EBCDIC, image, or local. The default is
binary.
failIfRemoteFileExists
A Boolean
specifying the action to be taken if the file already exists. The
default is true.
Boolean.
This example appends the content of test.ssc to the content of the existing test.ssc file on the remote machine:
<!--SCRIPT
ftpSession = new FTP ("ftpserv", "anonymous", "sam@sybase.com");
if( !ftpSession.PutDocumentWithAppend("test.ssc", "test.ssc")) {
document.writeln( ftpSession.GetErrorCode() );
document.writeln( ftpSession.GetErrorInfo() );
}
ftpSession.Disconnect();
-->
FTP.PutFile( remoteFileName, localFileName [, transferType, failIfRemoteFileExists] )
Puts a file to the FTP server from the Dynamo machine. The parameters are:
remoteFileName
The
name of the file on the remote machine.
localFileName
The
name of the file on the local machine.
transferType
Can
be one of ASCII, binary, EBCDIC, image, or local. The default is
binary.
failIfRemoteFileExists
A Boolean
specifying the action to be taken if the file already exists. The
default is true.
Boolean.
This example puts a file on the FTP server:
<!--SCRIPT
ftpSession = new FTP ("ftpserv", "anonymous", "sam@sybase.com");
if( !ftpSession.PutFile("test.doc", "g:\\dynamo\\ftp\\test.doc")) {
document.writeln( ftpSession.GetErrorCode() );
document.writeln( ftpSession.GetErrorInfo() );
}
-->
FTP.PutFileWithAppend( remoteFileName, localFileName [, transferType ] )
Similar to the PutFile
method,
except that if a file already exists on the remote machine, the
file is appended to the end. If the file does not already exist,
a new one is created. The parameters are:
remoteFileName
The
name of the file on the remote machine.
localFileName
The
name of the file on the local machine.
transferType
Can
be one of ASCII, binary, EBCDIC, image, or local. The default is
binary.
Boolean.
This example appends the text in the file test.txt to an existing file called test.txt on the FTP server:
<!--SCRIPT
ftpSession = new FTP ("ftpserv", "anonymous", "sam@sybase.com");
if( !ftpSession.PutFileWithAppend("test.txt", "g:\\dynamo\\ftp\\test.txt")) {
document.writeln( ftpSession.GetErrorCode() );
document.writeln( ftpSession.GetErrorInfo() );
}
-->
FTP.RemoveDirectory( directoryName )
Removes a directory from the FTP server. directoryName is the directory to remove.
Boolean.
This example deletes a directory called Dynamo from the FTP server:
<!--SCRIPT
ftpSession = new FTP ("ftpserv", "anonymous", "sam@sybase.com");
if( !ftpSession.RemoveDirectory( "Dynamo")) {
document.writeln( ftpSession.GetErrorCode() );
document.writeln( ftpSession.GetErrorInfo() );
}
ftpSession.Disconnect();
-->
FTP.RetrieveCurrentDirectory( )
Retrieves the current directory name from the FTP server.
String.
This example displays the current FTP directory:
<!--SCRIPT
ftpSession = new FTP ("ftpserv", "anonymous", "sam@sybase.com");
ftpSession.ChangeCurrentDirectory("Dynamo");
curdir = ftpSession.RetrieveCurrentDirectory();
document.WriteLn( curdir );
ftpSession.Disconnect();
-->
FTP.RenameFile( oldFileName, newFileName )
Renames a file on the FTP server. The parameters are:
oldFileName
The name
of the existing file on the FTP server.
newFileName
The new name for
the file.
Boolean.
This example renames a file on the FTP server from test.txt to newtest.txt:
<!--SCRIPT
ftpSession = new FTP ("ftpserv", "anonymous", "sam@sybase.com");
if( !ftpSession.RenameFile("test.txt", "newtest.txt")) {
document.writeln( ftpSession.GetErrorCode() );
document.writeln( ftpSession.GetErrorInfo() );
}
ftpSession.Disconnect();
-->
FTP.RetrieveData( remoteFileName [, transferType] )
Retrieves data from the FTP server and turns it into a DynaScript variable. The parameters are:
remotefileName
The
name of the file on the remote machine.
transferType
Can
be one of ASCII, binary, EBCDIC, image, or local. The default is
binary.
String or binary.
This example retrieves data from a file on an FTP server and displays the value:
<!--SCRIPT
ftpSession = new FTP ("ftpserv", "anonymous", "sam@sybase.com");
lname = ftpSession.RetrieveData("putdata.ssc");
document.WriteLn("last name: " + lname);
ftpSession.Disconnect();
-->
FTP.RetrieveDirectoryListing( [ directoryName ] )
Returns a directory listing from the FTP server. If you do not provide a directory name, a directory listing from the current directory is provided.
List of strings.
This example displays a directory listing for the FTP server:
<!--SCRIPT
ftpSession = new FTP ("ftpserv", "anonymous", "sam@sybase.com");
dir = ftpSession.RetrieveDirectoryListing();
document.WriteLn("The FTP directory listing is: " + dir);
ftpSession.Disconnect();
-->
FTP.RetrieveDocument( remoteFileName, documentName [, connectionName, transferType, failIfLocalFileExists] )
Retrieves a document from the FTP server and stores it in a PowerDynamo Web site. The parameters are:
remoteFileName
The
name of the file on the remote machine.
documentName
The
name of the file on the local machine.
connectionName
The
name of the connection to be associated with the document. The default
is <inherited>.
transferType
Can
be one of ASCII, binary, EBCDIC, image, or local. The default is
binary.
failIfLocalFileExists
A Boolean
specifying the action to be taken if the file already exists. The
default is true.
Boolean.
This example retrieves a document from the FTP server called test.ssc and stores it in a PowerDynamo Web site:
<!--SCRIPT
ftpSession = new FTP ("ftpserv", "anonymous", "sam@sybase.com");
if( !ftpSession.RetrieveDocument("test.ssc", "test_returned.ssc")) {
document.writeln( ftpSession.GetErrorCode() );
document.writeln( ftpSession.GetErrorInfo() );
}
ftpSession.Disconnect();
-->
FTP.RetrieveFile( remoteFileName, localFileName [, transferType, failIfLocalFileExists] )
Retrieves a file from the FTP server and saves it to the local machine. The parameters are:
remoteFileName
The
name of the file on the remote machine.
localFileName
The
name of the file on the local machine.
transferType
Can
be one of ASCII, binary, EBCDIC, image, or local. The default is
binary.
failIfLocalFileExists
A Boolean
specifying the action to be taken if the file already exists. The
default is true.
Boolean.
This example retrieves a file from the FTP server and places it on the local machine:
<!--SCRIPT
ftpSession = new FTP ("ftpserv", "anonymous", "sam@sybase.com");
if( !ftpSession.RetrieveFile( "test.txt", "g:\\Dynamo\\Ftp\\test.txt" )) {
document.writeln( ftpSession.GetErrorCode() );
document.writeln( ftpSession.GetErrorInfo() );
}
ftpSession.Disconnect();
-->
FTP.RetrieveFileWithAppend( remoteFileName, localFileName [, transferType ] )
Similar to the RetrieveFile
method,
except if the file already exists locally, the remote file is appended
to the end. If the file does not exist a new one is created. The
parameters are:
remoteFileName
The
name of the file on the remote machine.
localFileName
The
name of the file on the local machine.
transferType
Can
be one of ASCII, binary, EBCDIC, image or local. The default is
binary.
Boolean.
This example retrieves a file from the FTP server and appends the content to a file called test.txt that already exists on the local machine:
<!--SCRIPT
ftpSession = new FTP ("ftpserv", "anonymous", "sam@sybase.com");
if( !ftpSession.RetrieveFileWithAppend( "test.txt", "g:\\Dynamo\\Ftp\\test.txt" )) {
document.writeln( ftpSession.GetErrorCode() );
document.writeln( ftpSession.GetErrorInfo() );
}
ftpSession.Disconnect();
-->
Copyright © 1999 Sybase, Inc. All rights reserved. |
![]() |