[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36
John Goerzen
jgoerzen at complete.org
Fri Apr 23 14:45:47 UTC 2010
The following commit has been merged in the master branch:
commit 59cc46615fb95f1515750d7b13a283a3a595a54c
Author: John Goerzen <jgoerzen at complete.org>
Date: Sun Oct 24 10:38:15 2004 +0100
FTP is WORKING
Keywords:
(jgoerzen at complete.org--projects/missingh--head--1.0--patch-116)
diff --git a/ChangeLog b/ChangeLog
index 4147f2c..0882743 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,19 @@
# arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--1.0
#
+2004-10-24 04:38:15 GMT John Goerzen <jgoerzen at complete.org> patch-116
+
+ Summary:
+ FTP is WORKING
+ Revision:
+ missingh--head--1.0--patch-116
+
+
+ modified files:
+ ChangeLog libsrc/MissingH/Network/FTP/Client.hs
+ libsrc/MissingH/Network/FTP/Parser.hs
+
+
2004-10-24 03:42:55 GMT John Goerzen <jgoerzen at complete.org> patch-115
Summary:
diff --git a/libsrc/MissingH/Network/FTP/Client.hs b/libsrc/MissingH/Network/FTP/Client.hs
index e30d845..e72d652 100644
--- a/libsrc/MissingH/Network/FTP/Client.hs
+++ b/libsrc/MissingH/Network/FTP/Client.hs
@@ -56,16 +56,17 @@ module MissingH.Network.FTP.Client(-- * Establishing\/Removing connections
-- * Directory listing
nlst, dir,
-- * File downloads
- getlines, getbinary,
+ getlines, getbinary, downloadbinary,
-- * File uploads
- putlines, putbinary,
+ putlines, putbinary, uploadbinary,
-- * File manipulation
rename, delete, size,
-- * Directory manipulation
cwd, mkdir, rmdir, pwd,
-- * Low-level advanced commands
FTPConnection(isPassive),
- transfercmd, ntransfercmd
+ transfercmd, ntransfercmd,
+ retrlines, storlines
)
where
import MissingH.Network.FTP.Parser
@@ -95,6 +96,7 @@ getresp h = do
logsend m = debugM "MissingH.Network.FTP.Client" ("FTP sent: " ++ m)
sendcmd h c = do logsend c
+ hPutStr (writeh h) (c ++ "\r\n")
getresp h
{- | Connect to the remote FTP server and read but discard
@@ -167,7 +169,7 @@ login h user pass acct =
connection object reflecting this) -}
setPassive :: FTPConnection -> Bool -> FTPConnection
-setPassive f b = f{isPassive = True}
+setPassive f b = f{isPassive = b}
{- | Finds the addres sof the remote. -}
makepasv :: FTPConnection -> IO SockAddr
@@ -185,7 +187,8 @@ makeport h =
do addr <- getSocketName (socket_internal h)
mastersock <- listenTCPAddr (listenaddr addr)
newaddr <- getSocketName mastersock
- result <- sendcmd h ("PORT " ++ toPortString newaddr)
+ ps <- toPortString newaddr
+ result <- sendcmd h ("PORT " ++ ps)
return (mastersock, result)
{- | Establishes a connection to the remote.
@@ -198,10 +201,13 @@ ntransfercmd h cmd =
then do
addr <- makepasv h
s <- connectTCPAddr addr
+ r <- sendcmd h cmd
+ forceioresp 100 r
return s
else do
masterresult <- makeport h
- forceioresp 100 (snd masterresult)
+ r <- sendcmd h cmd
+ forceioresp 100 r
acceptres <- accept (fst masterresult)
sClose (fst masterresult)
return (fst acceptres)
@@ -209,8 +215,6 @@ ntransfercmd h cmd =
s <- sock
newh <- socketToHandle s ReadWriteMode
hSetBuffering newh (BlockBuffering (Just 4096))
- r <- sendcmd h cmd
- forceioresp 100 r
return (newh, Nothing)
{- | Returns the socket part from calling 'ntransfercmd'. -}
@@ -284,10 +288,21 @@ is the filename. -}
putlines :: FTPConnection -> String -> [String] -> IO FTPResult
putlines h fn input = storlines h ("STOR " ++ fn) input
-{- | Puts data in the specified file in binary. Ths first string is the filename. -}
+{- | Puts data in the specified file in binary. The first string is the filename. -}
putbinary :: FTPConnection -> String -> String -> IO FTPResult
putbinary h fn input = storbinary h ("STOR " ++ fn) input
+{- | Uploads a file from disk in binary mode. Note: filename is used for both local and remote. -}
+uploadbinary :: FTPConnection -> String -> IO FTPResult
+uploadbinary h fn = do input <- readFile fn
+ putbinary h fn input
+
+{- Downloads a file from remote and saves to disk in binary mode. Note: filename is used for both local and remote. -}
+downloadbinary :: FTPConnection -> String -> IO FTPResult
+downloadbinary h fn = do r <- getbinary h fn
+ writeFile fn (fst r)
+ return (snd r)
+
{- | Retrieves a list of files in the given directory.
FIXME: should this take a list of dirs? -}
diff --git a/libsrc/MissingH/Network/FTP/Parser.hs b/libsrc/MissingH/Network/FTP/Parser.hs
index c813c30..743f33b 100644
--- a/libsrc/MissingH/Network/FTP/Parser.hs
+++ b/libsrc/MissingH/Network/FTP/Parser.hs
@@ -52,7 +52,7 @@ import MissingH.List
import MissingH.Bits
import MissingH.Str
import MissingH.Logging.Logger
-import Network.Socket(SockAddr(..), PortNumber(..), inet_addr)
+import Network.Socket(SockAddr(..), PortNumber(..), inet_addr, inet_ntoa)
import System.IO(Handle, hGetContents)
import System.IO.Unsafe
import Text.Regex
@@ -213,13 +213,13 @@ Example:
> toPortString (SockAddrInet (PortNum 0x1234) (0xaabbccdd)) ->
> "170,187,204,221,18,52"
-}
-toPortString :: SockAddr -> String
-toPortString (SockAddrInet (PortNum port) hostaddr) =
- let wport = fromInteger(toInteger(port))::Word32
- whost = fromInteger(toInteger(hostaddr))::Word16
- in
- (genericJoin "," . getBytes $ whost) ++ "," ++
- (genericJoin "," . getBytes $ wport)
+toPortString :: SockAddr -> IO String
+toPortString (SockAddrInet port hostaddr) =
+ let wport = (fromEnum(port))::Int
+ in do
+ hn <- inet_ntoa hostaddr
+ return ((replace "." "," hn) ++ "," ++
+ (genericJoin "," . drop 2 . getBytes $ wport))
toPortString _ =
error "toPortString only works on AF_INET addresses"
--
haskell-testpack
More information about the Pkg-haskell-commits
mailing list