1c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair/*
2c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * Copyright 2007 the original author or authors.
3c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair *
4c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * Licensed under the Apache License, Version 2.0 (the "License");
5c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * you may not use this file except in compliance with the License.
6c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * You may obtain a copy of the License at
7c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair *
8c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair *      http://www.apache.org/licenses/LICENSE-2.0
9c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair *
10c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * Unless required by applicable law or agreed to in writing, software
11c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * distributed under the License is distributed on an "AS IS" BASIS,
12c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * See the License for the specific language governing permissions and
14c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * limitations under the License.
15c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair */
16c1de24f1bfa6699e54b069e300af5e4246b34a34chrismairpackage org.mockftpserver.stub.example;
17c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair
18c1de24f1bfa6699e54b069e300af5e4246b34a34chrismairimport org.apache.commons.net.ftp.FTPClient;
19c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair
20c1de24f1bfa6699e54b069e300af5e4246b34a34chrismairimport java.io.IOException;
21c1de24f1bfa6699e54b069e300af5e4246b34a34chrismairimport java.net.SocketException;
22c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair
23c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair/**
24c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * Simple FTP client code example.
25c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair *
26c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * @version $Revision$ - $Date$
27c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair *
28c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * @author Chris Mair
29c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair */
30c1de24f1bfa6699e54b069e300af5e4246b34a34chrismairpublic class FtpWorkingDirectory {
31c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair
32c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    private String server;
33c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    private int port;
34c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair
35c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    /**
36c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair     * Return the current working directory for the FTP account on the server
37c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair     * @return the current working directory
38c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair     * @throws SocketException
39c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair     * @throws IOException
40c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair     */
41c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    public String getWorkingDirectory() throws SocketException, IOException {
42c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair        FTPClient ftpClient = new FTPClient();
43c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair        ftpClient.connect(server, port);
44c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair        return ftpClient.printWorkingDirectory();
45c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    }
46c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair
47c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    /**
48c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair     * Set the hostname of the FTP server
49c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair     * @param server - the hostname of the FTP server
50c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair     */
51c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    public void setServer(String server) {
52c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair        this.server = server;
53c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    }
54c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair
55c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    /**
56c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair     * Set the port number for the FTP server
57c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair     * @param port - the port number
58c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair     */
59c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    public void setPort(int port) {
60c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair        this.port = port;
61c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    }
62c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair
63c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair}
64