Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
node-ftp-server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mickael Gomez
node-ftp-server
Commits
4596bac3
Commit
4596bac3
authored
4 years ago
by
Nicolas Fernandes
Browse files
Options
Downloads
Patches
Plain Diff
authent anonymous
parent
0bf26ea7
No related branches found
No related tags found
1 merge request
!2
Refacto/commands
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
messages.js
+6
-0
6 additions, 0 deletions
messages.js
modules/AuthentFTP.js
+53
-0
53 additions, 0 deletions
modules/AuthentFTP.js
modules/Server.js
+7
-43
7 additions, 43 deletions
modules/Server.js
utils/responseUtils.js
+11
-0
11 additions, 0 deletions
utils/responseUtils.js
with
78 additions
and
43 deletions
.gitignore
+
1
−
0
View file @
4596bac3
node_modules/
.idea/codeStyles/
This diff is collapsed.
Click to expand it.
messages.js
0 → 100644
+
6
−
0
View file @
4596bac3
const
messages
=
{
220
:
'
FTP server (vsftpd)
'
,
230
:
'
230 Already logged in.
'
,
331
:
'
Please specify the password.
'
,
530
:
'
Please FTPConnection with USER and PASS.
'
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
modules/AuthentFTP.js
0 → 100644
+
53
−
0
View file @
4596bac3
import
{
write
}
from
"
../utils/responseUtils
"
;
export
default
class
AuthentFTP
{
constructor
(){
this
.
login
=
null
;
this
.
password
=
null
;
}
async
serverResponse
(
data
,
socket
)
{
let
response
;
const
dataArray
=
data
.
toString
().
replace
(
/
\n
|
\r
/g
,
''
).
split
(
"
"
);
switch
(
dataArray
[
0
])
{
case
"
AUTH
"
:
response
=
"
530 Please FTPConnection with USER and PASS.
"
;
break
;
case
"
USER
"
:
response
=
this
.
userCmd
(
dataArray
);
break
;
case
"
PASS
"
:
response
=
this
.
passCmd
();
if
(
response
===
true
)
return
;
break
;
default
:
response
=
"
530 Please FTPConnection with USER and PASS.
"
;
}
const
clientResponse
=
await
write
(
socket
,
response
);
this
.
serverResponse
(
clientResponse
,
socket
);
}
userCmd
(
data
)
{
if
(
this
.
connected
)
{
return
`530 Can't change from guest user.`
;
}
else
if
(
data
[
1
]
&&
data
[
1
].
toLowerCase
()
===
'
anonymous
'
)
{
this
.
login
=
data
[
1
].
toLowerCase
();
return
'
331 Please specify the password.
'
;
}
else
{
return
'
530 This FTP server is anonymous only.
'
;
}
}
passCmd
()
{
if
(
this
.
connected
)
{
return
'
230 Already logged in.
'
;
}
else
if
(
this
.
login
==
null
)
{
return
'
503 Login with USER first.
'
;
}
else
if
(
this
.
login
==
'
anonymous
'
)
{
this
.
connected
=
true
;
this
.
password
=
""
;
return
'
230 Login successful.
'
;
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
modules/Server.js
+
7
−
43
View file @
4596bac3
import
{
createServer
}
from
'
net
'
;
import
FileSystem
from
'
./FileSystem.js
'
;
import
{
write
}
from
"
../utils/responseUtils
"
;
import
authent
from
'
./AuthentFTP.js
'
export
default
class
Server
{
constructor
()
{
this
.
server
=
createServer
(
socket
=>
this
.
init
(
socket
));
this
.
server
.
listen
(
process
.
env
.
PORT
,
()
=>
console
.
log
(
'
Server created
'
));
this
.
pasv
();
}
async
init
(
socket
)
{
console
.
log
(
'
Client connected
'
);
this
.
login
=
null
;
this
.
password
=
null
;
this
.
connected
=
false
;
const
data
=
await
this
.
write
(
socket
,
'
220 FTP server (vsftpd)
'
);
const
data
=
await
write
(
socket
,
'
220 FTP server (vsftpd)
'
);
const
fs
=
new
FileSystem
();
this
.
connected
=
await
authent
.
serverResponse
(
data
,
socket
)
this
.
serverResponse
(
data
,
socket
,
fs
);
socket
.
on
(
'
end
'
,
()
=>
console
.
log
(
'
Closed
'
));
}
...
...
@@ -25,7 +24,7 @@ export default class Server {
const
dataArray
=
data
.
toString
().
replace
(
/
\n
|
\r
/g
,
''
).
split
(
"
"
);
switch
(
dataArray
[
0
])
{
case
"
AUTH
"
:
response
=
"
530 Please
logi
n with USER and PASS.
"
;
response
=
"
530 Please
FTPConnectio
n with USER and PASS.
"
;
break
;
case
"
USER
"
:
response
=
this
.
userCmd
(
dataArray
);
...
...
@@ -46,48 +45,13 @@ export default class Server {
break
;
}
const
clientResponse
=
await
this
.
write
(
socket
,
response
);
const
clientResponse
=
await
write
(
socket
,
response
);
this
.
serverResponse
(
clientResponse
,
socket
);
}
/**
* Write data to the socket buffer to execute the provided command
* @param {string} command
* @return {Promise<String>} Resolving on response from the server
*/
write
(
socket
,
command
)
{
return
new
Promise
(
resolve
=>
{
socket
.
once
(
'
data
'
,
buffer
=>
resolve
(
buffer
.
toString
()));
socket
.
write
(
`
${
command
}
\r\n`
);
});
}
userCmd
(
data
)
{
if
(
this
.
connected
)
{
return
`530 Can't change from guest user.`
;
}
else
if
(
data
[
1
]
&&
data
[
1
].
toLowerCase
()
===
'
anonymous
'
)
{
this
.
login
=
data
[
1
].
toLowerCase
();
return
'
331 Please specify the password.
'
;
}
else
{
return
'
530 This FTP server is anonymous only.
'
;
}
}
passCmd
()
{
if
(
this
.
connected
)
{
return
'
230 Already logged in.
'
;
}
else
if
(
this
.
login
==
null
)
{
return
'
503 Login with USER first.
'
;
}
else
if
(
this
.
login
==
'
anonymous
'
)
{
this
.
connected
=
true
;
this
.
password
=
""
;
return
'
230 Login successful.
'
;
}
}
pasv
()
{
//serveur qui ecoute sur le portData
const
serverData
=
createServer
(
socket
=>
this
.
write
(
socket
,
this
.
data
));
const
serverData
=
createServer
(
socket
=>
write
(
socket
,
this
.
data
));
serverData
.
listen
(
0
,
()
=>
console
.
log
(
'
Server data created
'
));
const
portData
=
serverData
.
address
().
port
;
const
response
=
`227 Entering passive mode (127,0,0,1,
${
Math
.
floor
(
portData
/
256
).
toString
()}
,
${
Math
.
floor
(
portData
%
256
).
toString
()}
)`
...
...
This diff is collapsed.
Click to expand it.
utils/responseUtils.js
0 → 100644
+
11
−
0
View file @
4596bac3
/**
* Write data to the socket buffer to execute the provided command
* @param {string} command
* @return {Promise<String>} Resolving on response from the server
*/
export
function
write
(
socket
,
command
)
{
return
new
Promise
(
resolve
=>
{
socket
.
once
(
'
data
'
,
buffer
=>
resolve
(
buffer
.
toString
()));
socket
.
write
(
`
${
command
}
\r\n`
);
});
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment