In order to browse, copy, move, upload or download files, you must first connect to a file system. A file system can be either your PC's hard drive (a local file system), or an FTP server (a remote file system). Almost all NeoFM/FTP actions require a file system connection, so one must be created before you can do anything else.


Opening a Connection to a Local File System

Opening a connection to a local file system is relatively simple. All you need to do is execute NeoFM/FTP fmConnectLocal action. For example:


fmConnectLocal "MyPC" ""


The first parameter "MyPC" is the Connection ID, which is simply the name that you want to use to refer to this file system connection in the future. It can be anything you like, but it's often easiest to use something short and descriptive. The Connection ID cannot be left blank.


The second parameter is optional and can contain an initial path the connection should point to after its opened. If the initial path is empty then the connection will open to the PC's "Desktop" folder.


Opening a Connection to a Remote File System

Before you can open a connection to a remote file system or FTP server, you will need the following:


  • Access to the Internet.
  • An FTP server. (This can be a web hosting account with FTP access.)
  • The Host URL used to connect to your FTP server.
  • Your FTP user name and password.


Once you have the above items, you can open a connection to your FTP server using the fmConnectRemote action. For example:


fmConnectRemote "MyFTP" "ftp.yourwebsite.com" "User=john;Password=applesauce;InitialPath=/webspace/httpdocs"


The first parameter "MyFTP" is the Connection ID, which is simply the name that you want to use to refer to this file system connection in the future. It can be anything you like, but it's often easiest to use something short and descriptive. The Connection ID cannot be left blank.


The second parameter is the Host URL which is the Internet address of your FTP server. The third parameter contains the user name, password and an optional initial path that you would like the connection to point to after it's opened.


After Opening a Connection

To tell if the fmConnectLocal or fmConnectRemote actions have been successful, you can monitor the variable screen of VisualNEO Win's debugger. When NeoFM/FTP successfully connects to a file system, your debugger should display the variable below:


MyPC.Status = Connected


MyPC is the Connection ID you selected. For local connections this variable will always contain the word "Connected". For remote connections, this variable will contain either "Connected" or "Disconnected" depending on the status of the connection.


Once a connection has been opened, you can perform a variety of actions based on the files and folders that the file system contains. These actions can be handled programmatically, behind the scenes without user interaction, or interactively by providing the user with a visual Explorer-style file browser.


For example, the following navigates to a folder on the C: drive called "Sales", selects all files with a ".txt" extension and silently sends them to the Windows recycle bin:


fmChangeDir "MyPC" "C:\Sales"

fmSelectSome "MyPC" "*.txt" "IncludeFiles=Yes;IncludeFolders=No"

fmRecycleSelected "MyPC" "GetConfirmation=No;ShowProgress=No"


For many types of applications, you will want to let the user view and select files themselves. For this, NeoFM/FTP includes a powerful, Explorer-style file browser. First you will need to use VisualNEO Win's Rectangle tool to define the location on the screen where you want the file browser to appear. Then use the fmShowFileBrowser action to attach the connection's file browser to the rectangle object. For example:


fmShowFileBrowser "MyPC" "Rectangle1"


When your publication runs, the rectangle will be replaced by a visual file browser linked to the connection's file system:


Rectangle object before fmShowFileBrowser

Rectangle object after fmShowFileBrowser


Opening More Than One Connection

If needed, you can open multiple local connections. For example, suppose you want to create a file manager application with two views of your hard drive so you can drag and drop files between the two. To do this, simply open two local connections:


fmConnectLocal "Client1" ""

fmConnectLocal "Client2" ""


Be sure to give each connection a different ID.


Next, use the fmShowFileBrowser action display a visual browser for each connection:


fmShowFileBrowser "Client1" "Rectangle1"

fmShowFileBrowser "Client2" "Rectangle2"


Similarly, you can open both a local and a remote connection at the same time:


fmConnectLocal "Local" ""

fmConnectRemote "Remote" "ftp.yourwebsite.com" "User=john;Password=applesauce;InitialPath=/webspace/httpdocs"


Or two remote connections:


fmConnectRemote "Remote1" "ftp.yourwebsite.com" "User=john;Password=applesauce;InitialPath=/webspace/httpdocs"

fmConnectRemote "Remote2" "ftp.anotherwebsite.com" "User=betty;Password=pancakes;InitialPath=/webspace/httpdocs/img"


When more than one visible file browser is open at the same time, only one is considered "active". At run time, users can activate a browser by clicking its tree view, list view, path bar or status bar. You can determine which one is active programmatically by examining the contents of the global [FMFTP.ActiveClient] variable. This can be very helpful when you want to apply actions only to the active file browser. For example:


fmSetFileBrowserProperties "[FMFTP.ActiveClient]" "ViewStyle=Thumbnails"


or


If "[[FMFTP.ActiveClient].SelCount]" ">" "0"

  fmRecycleSelected "[FMFTP.ActiveClient]" "GetConfirmation=Yes;ShowProgress=Yes"

EndIf


Closing a Connection

When you're finished working with a file system, you can close the connection using the fmDisconnect action. For example:


fmDisconnect "MyFTP"


This is more important for remote connections than local ones. However, if you forget to close a connection, NeoFM/FTP will do it for you automatically when your publication shuts down.