Chapter 3 DynaScript Predefined Objects


FTP methods

The FTP object has these methods:

ChangeCurrentDirectory method

Syntax

FTP.ChangeCurrentDirectory( directoryName )

Description

Changes the current directory name on the FTP server.

Return

Boolean.

Example

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() );
}
-->

Connect method

Syntax

FTP.Connect( )

Description

Connects to the FTP server.

Example

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 );
-->

CreateDirectory method

Syntax

FTP.CreateDirectory( directoryName )

Description

Creates a directory on the FTP server.

Return

Boolean.

Example

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() );
}
-->

DeleteFile method

Syntax

FTP.DeleteFile( fileName )

Description

Deletes a file from the FTP server.

Return

Boolean.

Example

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();
-->

Disconnect method

Syntax

FTP.Disconnect( )

Description

Disconnects from the FTP server.

Example

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();
-->

GetErrorCode method

Syntax

FTP.GetErrorCode( )

Description

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.

Return

Integer.

Example

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() );
}
-->

GetErrorInfo method

Syntax

FTP.GetErrorInfo( )

Description

Returns a string containing an error message, either from the FTP server or from PowerDynamo.

Return

String.

Example

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() );
}
-->

PutData method

Syntax

FTP.PutData( remoteFileName, localData [,transferType, failIfRemoteFileExists] )

Description

Stores Dynamo data to the FTP server from a local machine. The parameters are:

Return

Boolean.

Example

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();

-->

PutDataWithAppend method

Syntax

FTP.PutDataWithAppend( remoteFileName, localData [, transferType] )

Description

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.

Return

Boolean.

Example

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();

-->

PutDocument method

Syntax

FTP.PutDocument( remoteFileName, documentName [, transferType ] )

Description

Copies a Dynamo Web site document to an FTP server. The parameters are:

Return

Boolean.

Example

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();
-->

PutDocumentWithAppend method

Syntax

FTP.PutDocumentWithAppend( remoteFileName, documentName [, tranferType, failIfRemoteFileExists] )

Description

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:

Return

Boolean.

Example

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();
-->

PutFile method

Syntax

FTP.PutFile( remoteFileName, localFileName [, transferType, failIfRemoteFileExists] )

Description

Puts a file to the FTP server from the Dynamo machine. The parameters are:

Return

Boolean.

Example

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() );
}
-->

PutFileWithAppend method

Syntax

FTP.PutFileWithAppend( remoteFileName, localFileName [, transferType ] )

Description

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:

Return

Boolean.

Example

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() );
}
-->

RemoveDirectory method

Syntax

FTP.RemoveDirectory( directoryName )

Description

Removes a directory from the FTP server. directoryName is the directory to remove.

Return

Boolean.

Example

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();
-->

RetrieveCurrentDirectory method

Syntax

FTP.RetrieveCurrentDirectory( )

Description

Retrieves the current directory name from the FTP server.

Return

String.

Example

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();
-->

RenameFile method

Syntax

FTP.RenameFile( oldFileName, newFileName )

Description

Renames a file on the FTP server. The parameters are:

Return

Boolean.

Example

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();
-->

RetrieveData method

Syntax

FTP.RetrieveData( remoteFileName [, transferType] )

Description

Retrieves data from the FTP server and turns it into a DynaScript variable. The parameters are:

Return

String or binary.

Example

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();
-->

RetrieveDirectoryListing method

Syntax

FTP.RetrieveDirectoryListing( [ directoryName ] )

Description

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.

Return

List of strings.

Example

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();
-->

RetrieveDocument method

Syntax

FTP.RetrieveDocument( remoteFileName, documentName [, connectionName, transferType, failIfLocalFileExists] )

Description

Retrieves a document from the FTP server and stores it in a PowerDynamo Web site. The parameters are:

Return

Boolean.

Example

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();
-->

RetrieveFile method

Syntax

FTP.RetrieveFile( remoteFileName, localFileName [, transferType, failIfLocalFileExists] )

Description

Retrieves a file from the FTP server and saves it to the local machine. The parameters are:

Return

Boolean.

Example

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();
-->

RetrieveFileWithAppend method

Syntax

FTP.RetrieveFileWithAppend( remoteFileName, localFileName [, transferType ] )

Description

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:

Return

Boolean.

Example

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.